[Solved] Game performance drops after a while

Hello. For the last year, I have been in development on a game. It works most similarly to Binding of Isaac.

My issue is with performance. My game has five main levels, and after level 4, the game will get significantly more laggy. However, if I start at level 5, the game won’t be laggy at all.

I have over 50 scenes, and many do the same thing as another. I have hundreds of images, but only around ten to twenty are on a level at once, with mostly small images (64x64). I have a few enemies on each “room” of the level and there can be duplicates in a room, so I have used some “for each”.

For solutions, I have not compressed the images, however I don’t think that is the problem. I haven’t tried lowering the for eaches by heightening the requirements, and I haven’t used external events.

I obviously haven’t provided the game, but in the profiler in the debugger, the main thing that consumes performance is the event group. For reference, if I start the game and go through to level 4, events will be at 1.15ms to 2.05ms. Once the lag hits, it can go as high as 75ms. I haven’t tried grouping the events, so if no solution is found, I could try that. However, since the lag can appear somewhat variably, it could require some time investment to move around the code a bit.

What could the issue be? It doesn’t feel like level five is consuming way more than the other levels, but it just feels like after some time it can get very laggy.

1 Like

Also, I don’t know if this will help, but I have a lot of collision checks in my game. I don’t know if this impacts performance much, but thought it could help.

When you change scenes from one to the next, is it with “Pause and start a new scene”, or with “Change to scene ...”?

Do you have any effects in the scenes?

I would suggest grouping the events to narrow down where the bottleneck is occurring. It’s the best way of identifying where the issue is occurring.

Collision detection can largely impact performance if a lot of checks are made. Since those checks (depending on how your event sheet is set up) will be done all at once every frame, that can be very taxing after a while. It would be worth it to try and use the distance between objects (usually found near collision in the menu list). Distance between objects uses a lot less computer power to figure out. Also on the GDevelop main youtube channel there is a video they just put out on performance optimization. That would be worth a look.

As a side note, make sure if you have any timers or checks that may be irrelevant, for example checking collision on an enemy that isnt even in the scene anymore, delete those timers and bury collision checks behind a number of instances check.


99% of my transitions are just “change to scene”. I also don’t have any effects. I was thinking about looking into it, but first I wanted to solve this issue. And yeah, I will look into grouping soon to see where the issue occurs.

Also, let’s say if I have an enemy called zombie. If I check collision with a “if zombie is in collision” then “…” all the time, is that bad? If so, I may look into distance between. And yeah, there are likely a few excessive checks I could look into. And thanks for the video suggestion!

Also, I don’t know if I said this exactly in my other posts, but the lag doesn’t just hit from level four to five. Depending on the player’s pace, it could even hit at level 4. And also, it does jump to those use higher values, instead of slowly getting more laggy.

I tested one room with less collision checks, but it seemed to run at the same rate as the other rooms. If anyone thinks it’s worth it to implement over every level to see if it changes things then I will, but otherwise I don’t think that is solution.

I think it’s something else because only one level is up at a time with “change scene”, and over 40m to an hour of playing the lag will hit and remain for the rest of the levels. Change scene could be the issue if it made the old rooms still run in the background, but otherwise that might not be it either.


Collision check reduction helps, but isn’t the ultimate source of the lag.

I wouldn’t think collisions are the cause. Are the events the same for all the scenes, or do they each have their own specific set of events?

Yeah you’d be right. It doesn’t seem like the collisions are the issue anymore. Don’t get me wrong it helps, but the lag is still there.

Ok, for layout, I have five levels, and each level has ten rooms that are put into scenes. Each scene in a level has more or less the same content as another, with the only difference being global variable checks.

If the lag happens over a specific time then it could be a data leak issue. YouTube has an issue like this right now with its “shorts” videos. Once you watch one after about an hour the whole app gets really laggy and slow. You have to close the app and restart it again to reset it. I would make sure all loose ends are tied up in your events so nothing is being called to exponentially or otherwise unused content being active.

This does sound very similar to my issue.

How do I fix this issue though? I have a few global variables running like a timer, hp, etc, but otherwise it’s hard to imagine anything else being the issue.

I would say there is probably a lot of unnecessary things running in the background in a scene, but when you “change to scene” doesn’t all the previous scenes stop?

If change to scene works as I think, I don’t know. If that isn’t the case, how do I stop old scenes? Because there would definitely be a lot of unnecessary things in that case.

Also, I know you said data leak, but I searched up memory leak and saw a few others with my same conditions and issue. “Lots of change to scenes, lags after a while”.

However, I don’t believe many of their solutions are particularly helpful, unless I’m missing one.

Also, I used task manager, and it was also telling me that, after a while, the cpu usage would rapidly rise. However, it wasn’t consistent with timing or level. It just seemed like it would rise after a certain amount of time, or a certain amount of scenes.

Do you know how many scenes aproximately? Or about how long? Im gonna test my game when i get home and see if i change the scene a bunch if anything happens. Im interested in finding out whats causing this. At this point though, i dont think anyone will be able to extrapolate further since we dont know what your code looks like. I understand that you dont want to put it oyt there since youve been working in it so long, but just some screen shots of your scene changes would help. Like we could test it on our computers and see if the same thing happens.

Big question: does it only slow down in preview, or does that happen if you export it as well?

For time, it usually takes around 40 minutes to an hour, but if I go fast it can take around 20 minutes. For scenes, it is always around the 60s to 70s mark.
Scenes are inconsistent because there are also a lot of cutscenes in between that don’t really impact performance, so if you don’t lag on a main level in the 60s, you will on a level in the 70s. Without cutscenes, it’s more like 40-43.

Also I have tried it both in preview and export, and it slows down in both.

For the screenshot, I have provided what a basic change to scene looks like in my game. It changes if you come in contact with the door after defeating the enemies, it will move you to the next level, and it will set a variable to a value, so when you spawn at the next room, you are close to the door you entered in.
The last pic is of a cutscene change, which is very simple.


Okay so, i am unable to replicate any slow down with a similar setup. My best guess at this point is to just keep cleaning shop until something changes. If there is an issue somewhere that compounds over time, you may accidentally fix it just by doing some streamlining. I have to ask, why so many scenes? Wouldnt using external layouts work better? As well, are all the scenes using the same set of events? Wouldnt it be simpler to use external events to keep cleaner code organization?

Also, for the code you provided, it looks like many events are using the same check but are not branched off of that similar check (if that makes any sense). If you want i could provide an example of what im talking about.

Sorry i couldnt be more help this time around. I really do hope you get this figured out. If you do, make sure to let us know here on the forum, so we can all learn from the experience. Good luck in advance!

1 Like

I don’t really know why I haven’t used external events. I guess I haven’t used it before so I’m not too familiar with it. Also, I had a lot of scene more so because of inexperience. I am now trying to condense everything, so that instead of there being five levels with ten scenes each, there would be five scenes with each room in the scenes.

I think I kinda understand what you are saying here.

It’s fine! Thank you for the help, as it taught me some valuable things anyways. If I figure this out, I will update this, though that may take a while. Good luck to you too!

A couple of notes about your screen snip :

Those global variables changes after the change scene will not get actioned - GDevelop is changing scene, it’s removed the current one. Modify the variables before the scene change action.

Likewise the subevents of those events (you’ve collapsed them in the screen snip) will never get actioned.

Also, why do you delete the Billy object and then recreate a Billy object? Why not just change the position of the Billy object?

Finally, you’ve got quite a few events that check if Finished5 = 4 or Pacifist = 1. You can put that condition into an event, and then have the checks of Billy in collision with a door object as a subevent :


Bu to the lagging issue - you could run developer tools (Ctrl + Shift + i) in the game while in preview mode and see if anything crops up there.

But I still think you should use event groups and the performance profiler to identify the bottle necks. Just guessing what the issue could be without the performance data is just flying blind.

1 Like

Thank you for the advice. Moving checks around like you mentioned in the second picture is great for optimizing and there is some noticeable return. Also with the delete thing I have utilized this as of today, I don’t know why I don’t instead just move the character. As far as the first tip goes though, it is likely better practice to do it your way, but the way I did it has worked.

But as far as the two dev tools go, they aren’t that useful. In a scene with lag and event grouping, the performance profiler will just have the old things but with increased values. Let’s say the main things that tax performance are the player, the enemies, and rendering. Once the lag hits, everything other than rendering will increase. And it’s not like I suddenly will have more code for the player or the enemies, it just seems like an accumulation of… something.

But I’m unsure of what that tells me. Even when I optimize the code, when it starts to get laggy it is still pretty bad. I got it from 50m - 75m to 20m, but that’s still way higher than normal.

It could be worthwhile to group individual items. If the “player group” is seeing an increase in render time in the profiler, go in and add subgroups to each set of events to see which ones specifically are increasing render time.

That said, there could be something else going on, like you have a bunch of “For each Object” events that create objects along with Trigger once (which doesn’t work, meaning it’s not being triggered once, so the objects are being created every frame, etc). The above method of adding even more subgroupings will let you narrow down which group of events are being impacted the most as time goes on, and potentially narrow the origin of your issue.

I have tried adding subgroups to those main event groups. For player, I added seven in areas I think could be taxing, but it doesn’t seem like any area is much more taxing than another. Granted some are, but if player goes from .6m to 20m, the highest one might be at 7m.

Also, does trigger once not work on for each? I do have quite a few of them, and usually they will help with either spawning or death. Though, I haven’t seen endless enemies, and it doesn’t seem to be the case in the profiler either.

Here is an example of the spawning thing I mentioned.


My issue with my game was that it seemed like after a long time/ a lot of scenes, the game would start to lag immensely.

I got suggestions about code, collision checks, and even for each objects, but nothing did the trick. Determined, I though my only two solutions were either rewriting my game, or trying to optimize.

However, a user named JonnyMangoes had a similar issue and simply corrected it by rolling back to version 5.0.130.

I wish I could have a solution that wasn’t version dependent, in case anyone else had this issue, but this seems to be the case here. Now, my game runs without lag.

Thanks to all those who helped me, there were a lot of good tips for optimization here.