Hello!
Most of my knowledge has been within the 3D scene of Godot, but I’ve been dabbling into 2D game development. I’ve made a little game that I feel is pretty polished, but I started to run into a few problems when it came to loading/preloading certain assets, and accessing stuff globablly throughout any “Scene”. Also, I like to work with shaders and certain effects that will globally be on the screen at all times (Like a CRT Shader or bloom effects!)
But that got me thinking, what if I were to structure my entire game around using only 1 Main scene, which will have a node to preload any assets i need (whether it be SFX, Music, Sprites etc); and also all the effects I previously mentioned, and then say I wanted to load the Main Menu or the Main Game scene, I would instantiate that rather then loading into a whole new scene for example.
Would this be a good design process behind a 2D game? I’m mostly just looking for peoples opinions on this idea
I do it in that way and find it very easy to work with. I have my main node (main scene) from where I instantiate or free children nodes that will represent different aspects of the game (main menu, battle, inventory, etc). This way things that have to be there always, like shaders or some GUI are there in the main always. And for any variable that needs to be global, I put it in a singleton (like the saved game resource). I don’t know how this approach compares in efficiency with loading into a whole new scene, but I would say it is more or less the same. You are just adding one level more in the hierarchy I think, and working as if your second level (1.root → 2.main) were your new root. Anyway, I would like to hear also from others their opinion.
The way I currently do it in a game I’m working on:
my startup scene loads other scenes/nodes I want to always be there, across “game scenes”. (By attaching directly to the root node (get_tree().root.add_child(…))
a GameManager singleton switches scenes depending on a global game state (e.g. main menu, in-game screen,…) using get_tree().change_scene_to_packed(…)
So, the startup scene installs the “always on” nodes, then asks the GameManager to switch to the main menu, thereby unloading itself.
What is the benefit of using change_scene_to_packed? In my approach, I only care about using add_child and queue_free for changing scenes, and I’m super comfortable with that. I mean I don’t understand the use case of change_scene_to_packed very well.
I started to do this, then I realised I was making a framework within a framework. I don’t do this any more. I do now use a global TransitionManager to manage my transitions, just to make them smoother and have something on the screen as other scenes load. However, I am not unloading and re-loading hefty graphics or scripts so I suppose every case is different.