I am starting to design a game which is quite UI heavy. After some research it seems the best way to approach this is to create separate scenes for each UI.
In starting I have just 3 UI scenes:
MainMenuUI
LocationUI
ShopUI
My main scene is named ‘GAME’ and I have added a child node to this called ‘UI’.
Then I have instatiated each of my UI scenes underneath.
So, my ‘GAME’ node2D tree looks like this:
GAME
-UI
-MainMenuUI
-ShopUI
-LocationUI
How do I go about scripting the visibilty of each of the instatiated nodes so only one shows up at once?
I am so sorry if my explanation is poor.
I just need to be able to swap each of the scenes.
add each node to array
loop array, disable every node
at the end enable the node that should be active.
Disabling the node is sort of undefined.
There are things that you can do to “disable” a node.
You can unparent it from everything. This will leave the node outside of the scene tree, it wont be “active”, no rendering/input/process, but the node is still present and you can later parent it back where you need.
You pick and chose what flags you have to switch on the node based on what you need. You want ui to stay visible but not react to input? Disable input flags. Want it to hide but still run process? - disable visible, but leave process flag.
If you want the node completely disabled unparenting it from the tree is the easiest.
But with UI, visible = false is usually enough, as it also removes the canvas transforms from the tree so node just stops existing in layouts like if you unparented it, but retains its position in the scene tree.
With UI visible = false and process_mode = Node.PROCESS_MODE_DISABLED is usually enough.