So the project I’m working on is huge with currently 23 scenes (there might be a few hundreds more in the future). The switching among levels are done by directly changing the scenes.
In the event sheet of each scene, there is collision detecting between the main character and ‘edge’, the invisible masks used for level switching. When the player touches the ‘edge’, the name of the next scene will be written in a scene variable. Then in the ‘Platformer Events’ (which is applied to all playable scenes) the screen turns black. When the screen is completely black the player will reach the next scene.
The ‘death’ variable is used to detect whether the player is entering the scene alive or entering the scene when reviving from death.
While running the preview (the same thing happens in the build), I found that if I frequently switch between two scenes the RAM usage will increase. At first it only takes around 1300 MB however after a few switches it goes up to 2000 MB. My project file is only about 270 MB large, and it seems to be extremely unusual for such huge RAM usage. Also I found that the graphic part of the game took most of the RAM (around 1000 MB). So I wonder if the RAM usage won’t be that large with level switching done by external layouts?
Also, most enemies and their corpses and weapons appear in multiple scenes. So I make them all global (this really sounds like a stupid idea). Now I’m having over… I don’t know, maybe 200+ global objects? Will it cause performance issues?
By the way, the behavior of the enemies are stored in external events and are used when the scene needs them. However, something common for all enemies, like, vision detecting and taking/causing damage are stored in the ‘Platformer Events’. Is there a way to optimize that?
I’m struggling with the optimization problem for over two weeks. I can’t continue my project until the problems can be solved. I tried methods like turning all my images into png8, starting the scene from the event sheet instead of the scene editor, optimizing the control of the player’s animation and collision checks, etc. Unfortunately the game still lags. The fps with the decorated scenes is around 20 - 30. Can it be solved by using external layouts and less global objects?
I would definitely recommend using external layouts for each level instead of a new scene. Assuming your levels share lots of the same objects and logic.
Speaking of which I would imagine Global Objects in GDevelop are never unreferenced completely, well I’m sure some instances will be, but the definition of the object will persist at least.
So, yeah, I think reducing your dependance on Global Objects will help reduce memory footprint.
Thanks! I would like to know more about switching scenes with external layouts. Like, how do I remove all the objects in the current layout while generating a new one?
Be prepared for a lot of work.
- Choose a scene to be your base scene like “Level”… maybe take Level 1 or whatever.
- Create an external layout from that base scene… perhaps named Level 2.
- Open the scene editor for the original Level 2 scene, zoom way out, drag and select everything, copy.
- Edit the new external layout for Level 2 and paste there.
- At this point you can repeat for each scene to external layout copy.
I don’t think there is a way to un-global your objects. Perhaps there is a way to do this by manually editing the JSON, but I don’t know. Just focus on the base scene you are using for the external layouts.
Close every tab expect the base scene before proceeding. Duplicate or re-create each global object as a normal object, then deleting the global, and then renaming the duplicate to have the original name. So these one object at a time, checking for errors or missing objects in your scenes. (If your base scene has global objects in it then you might try pressing CTRL-Z to undo the objects being deleted in the base scene. I’ve had luck with using this trick to rename objects… hopefully deleting the globals in the base scene won’t affect the external layouts until you are done renaming). Also make sure when you are deleting the global to say not to delete references to that global.
Not via the editor.
I’ve managed by hacking the game.json file. I compared a scene sprite with a global sprite, and applied the difference. Not sure if it’s a safe way to do it, or what it may mess up behind the scenes, but it seemed to be ok for me.
If you do try this, be sure to make a backup of your game first.
I’ll try this. By the way, is there a way to maintain the events of one single level (not the whole stage) while using external layouts? For example in 2 - 4 the player can unlock a new ability, then can I still create events that only work for this specific level?
The “Include External Events” link event can be put inside of a conditional, or as a sub-event.