How to solve lag

How do i keep the game run smoothly with no lag? Is it possible to keep the objects like particles and light inactive to reduce the lag?

Anyone? :frowning:

Generally, you need to make sure you trigger events only when needed and only as many times as needed.
For example:

When you check collision, you may need to consider to use a timer and check collision only every 0.2 seconds, this way the collision check is going to be triggered only 5 times a second instead of 30 or 60.
Also, try to avoid using pixel perfect collision checking as it is extremely resource hungry. For the most part, collision shapes and simple shapes should work just fine but in case you need a complex shape try to use few polygons only, the less is better.

Avoid using multiple conditions in the same event, try to brake up the conditions in to sub events instead. For example if you want to create a button that can be clicked and you want to do something when it is clicked:

Event: If Left mouse is pressed -sub_event: mouse is over button : do something

In this example, if the mouse is over the button is going to be checked only if the mouse is pressed, this way you don’t waste resources on checking if the mouse is over the button even if it don’t even need to be checked (the mouse is not pressed).

In case you are deleting, creating objects on the fly, before trigger any events on those objects, check if there is any objects in the scene at all. For example, bullet. Before try to move a bullet and check collision with a bullet, make sure there is any bullet in the scene.

Event: if number of Bullet is > 0 -sub_event: bullet is in collision with enemy --sub_event: Do - 10 to health of enemy health of enemy <= 0 then delete enemy

It a complete waste of resources to try to check conditions on something that don’t even exist. In case something can be deleted from the scene or created on the fly, always check if there is any in the scene before doing anything to them, with them.

Finally, it always a good practice do not use huge images in your game. Instead of scaling down too big images, always make them to be just the right size to fit the game.

This is all I can think of right now but I need to admit, even with all these techniques I have never been able to make a smooth experience in GDevelop. From my experience even if you just try to move an object in GDevelop, sometime it lags without doing anything else, but move. I do experience it on both HTML5 and native and even in the game 4ian is making, so I’m pretty sure there must be a problem in GD somewhere but I’m not an expert on this topic maybe I’m just overlook something but it a fact, every now and then someone always show up with weird lag problem, maybe this time it you and everything I have suggested you have already tried.

4ian has mentioned this year he is going to pay more attention on performance improvement and he would like to finish the game he is making so I really hope this mysterious lags that people experience time to time going to be solved, until then you can try to make to most out of it with my suggestions and hopefully others may going to have a few more tips as well. Actually I would be also interested to hear some thoughts on this topic.

1 Like

Are you sure it’s not just that you didn’t enable Vsync (for native games at least), it could be the cause of those mysterious apparent “jumps” when objects are moving. They are not a lot of things to improve in the native games, and nothing should cause random FPS drop.

Yes I’m sure, Vsync is enabled. I’m wondering if it could be related to graphics driver because with my old GT430 I did not experienced lag, I do experience the lag since I have upgraded my graphics to GTX750 Ti. Also it doesn’t seem to be the same for everyone. Some people do experience the lag while others don’t or under different circumstances.

Although I’m sure there’s a lot to optimize within my game, I’ve been able to run the most resource-heavy AAA games on my computer, so there has to be a bug or a compatibility issue with the newer machines.

I love GDevelop and if the lag issues could be fixed it would be perfect for my needs.

Is it a very large project? There could be performance issues related to expensive events launched every frame (lot of collision checks, for example), and can be difficult to catch in large projects :neutral_face:
You could send me the project to check it personally too :wink:

Thanks, it is a large project indeed, It’s been in the making for the last year and a half. Even though I’m mostly an animator and I had to spend a lot of time optimizing the game, I’m fairly confident that the code isn’t an issue. I’ve made sure that the events mostly trigger only when needed (no pixel perfect collisions, check whether casting animation is finished only if player is casting and the animation sprite number is >0 etc. In other words, at any given moment only a limited number of events are active ).

At one point I had even lowered the frame rate of all the animations to a barely acceptable minimum. (It’s pixel art graphics so the sprites weren’t big to begin with). These actions didn’t affect the lag considerably. So I just made a new empty project and run the profiler (Vsync is on). These are the results:

imgur.com/a/ckNTH

As you can see, there are frame rate peaks (or rather drops) every couple of seconds. I’m running Windows 10, Intel core i7 CPU, 16GB RAM. There has to be a compatibility problem, since when I was using an older laptop I didn’t experience almost any frame drops.

I’m very grateful for GDevelop, I have learned so much, both programming logic-wise and game design-wise (with an almost non-existent experience curve). I don’t want to put too much pressure on somebody who’s giving us all this just out of their good will and for free, but I have to say that if these issues are not addressed, any further development is overshadowed by something that makes GDevelop games look quite unprofessional (at least on similar systems to mine).

Try explaining to the “PC-master-race-hot-FPS-git gud” guy why your 2D indie game frame-skips every couple of seconds.

Thanks for replying, hope we find a solution.

This is not a real solution, but while working on a windows demo, I experienced the same issues, but only on some computers (difficult to tell why). Anyhow, disabling vsync made the game at least run smoothly on all of them.

Hi @CSEREN,

you are replying to a post that is 7 years old. Since then many things have changed, even the engine (it was Gdevelop 4 at that time). Even though what you wrote is not related to the engine specifically, it would be more beneficial if you would make a new topic in which you describe your approach to improve performance.

Oh, it was my mistake. I commented on the wrong post. It seems that the post was deleted, and I did not notice that I was moved to the wrong page