Making game run faster


#1

Hello, my game is starting to lag a lot and it also takes quite a long time to load. I’ve been getting rid of unnecessary objects and events to try to make it faster. I have a few questions about this:

If I make events say “trigger once” will that help the game run faster? I was thinking that maybe some of these events are trying to run all the time and slowing down the game. For example, I have lots of inventory slots and when each one’s global variable is a particular number, it changes the animation of the slot. Would adding “trigger once” to all those events help speed up the game?

Another thing I realized is I have some animations with many frames that all have the same image but with different file names. For example, if I were making a character blink, I would a copy a frame numerous times in Pixel and then eventually make a new frame that has the image change to the character with its eyes closed. There would be many images of the character with its eyes open, and even though they all look the same, they would have different file names. Does it make a difference to the run speed if I make the animation use less files even though the number of frames is still the same?

My last question is I have a lot of files in my game folder which are no longer relevant to the game such as sprites that are not used and older versions of my game (I frequently re-save my projects with new names because sometimes my projects get malformed and cease to open). Does the amount of files in the folder effect how long it takes to open the game and how fast the game runs? I was thinking when I’m done making my game more efficient I can save it into a new folder that has less irrelevant files but I’m not sure if this would make a difference.


#2

Hi!
For the repeating blinking sprites, I suggest to use only one sprite for one state and one other for the blinking state, and then change them from code with a timer or a counter. Every sprite uses memory and can slow the process (altough mostly modern computers can handle a lot of sprites in memory without hassle).
For repeating events, ensure that are only processed when needed making them as subevents of conditionals, for example.


#3

OK.

If my event is constantly checking for something like what variable something is, does it make a difference if I add the condition “Trigger once”?

Also I noticed that if I click on resources, there are hundreds of images that aren’t actually used in any of the scenes. Are these getting loaded every time I run the game? Maybe this is why it takes so long to preview the game?


#4

If my event is constantly checking for something like what variable something is, does it make a difference if I add the condition “Trigger once”?

You should use “trigger once” if the event only happens one time. Checking some tens of variables every frame shouldn’t make your game slow. Another thing would be to check thousands every tick.

Also I noticed that if I click on resources, there are hundreds of images that aren’t actually used in any of the scenes. Are these getting loaded every time I run the game? Maybe this is why it takes so long to preview the game?

I think GDevelop only load stuff that will be used in the scene, but if you are unsure about that, clear your project of unused things.

If you think that you have events that doesn’t need to be checked every frame, you can activate them with a counter or a timer, and that can save you some computing power, but even old computers can handle a lot of data, so I’m not sure if that could give you a real permormance impact.


#5

This is an optimization page on the wiki, it is an draft, let me know if this help you.

(The page will be moved in next months, tag me here if the link is broken)


#6

Thanks. I tried to optimize it but it’s still lagging. I don’t know why… I’m going to try it on another computer but I’m getting an error message and it won’t let me export it to the web. It says “Error while lauching the build of the game.
Request failed with status code 504”. Does anyone know why this is happening?


#7

Ah! I think I found out what was slowing down my game. I wasn’t really using any sub events. I can see in the debugger profiler that using sub events seems to be making the game run more efficiently. Thanks for that wiki page, Bouh!