There is one basic thing in Godot I still don't understand. I was told that one should make every accessible scene/node part of one bigger tree of game's scenes. However, if I want to create some objects – let's say bullets – out of nowhere, they have to be already part of the scene tree, already loaded somewhere. I get it that the information of the node is accessible faster or something like that, but doesn't this also mean there's always at least one bullet node active somewhere in the game area messing around (even though I want there to be no single particular active nodes of that type)? Should I deactivate this particular node somehow (until it is needed), place it into deactivated area, or does Godot lose track of the node if I do anything like this? How should I proceed?

Also, how do I deactivate stuff in general anyway? For example if I want to deactivate everything outside (view) area, is it done with some code or in the editor somehow? My concern about deactivation also applies with separate levels, rooms and every thing that should exist only temporarily/sequentially. I want to get started and tried reading the docs but I'm dumb.

It doesn't appear there is an easy switch to deactivate a node. However, I found this post, which seems to show two ways to accomplish this. https://godotengine.org/qa/49696/how-to-disable-enable-a-node?show=49754#a49754

Basically you either remove the node from the root tree (the object can still exist in memory and can be added back later or deleted and re-instanced), or manually disabling each property (visible to false, set process to false, disable collision, etc.). You can probably abstract this into a function, so you don't have duplicated code. I haven't really tried it yet, so I don't know what the performance hit for the options are.

Hope that helps.

Thanks for the reply. Seems like it's depending on the situation but set_process(false) is probably one of the closest I was looking for and didn't know yet. (I was already familiar with hide() and remove_child().) For the sake of optimization I think this is very important feature to have, if one is dealing with a world much bigger than the screen.

About remove_child() though, can I use that to remove a node from the tree and then instance it again using only add_child() pretending like I never destroyed it in the first place? So remove_child() does not remove the node from memory completely? Is there some more radical function to do the memory liberation if needed? Also if I understood correctly, has_node() function also checks whether the node exists (is removed or not). I wonder if I should check the existence of nodes and their instances (id) differently...

I assume, for area based deactivation the best option might be to use a group. A function checks all the nodes set in the group and then I make a function like "inside_area()" (if there's no similar function already) and deactivate/de-process/remove all the grouped nodes outside the area. Ideally I would design my game so that in the main scene I could only remove one big node-branch of relevant game scenes at once, but I doubt that way I only end up creating many nodes purely for organizing other nodes. I don't know if it's bad but maybe the group-option is meant for this kind of situations better... Correct my brainstorm if I'm wrong somewhere. xD

I just tested the remove_child()/add_child() method. It actually works well. I even did it as my sprite was in mid-air and when I added it back it was in the same place and continued jumping. So that seems like a really easy way to go. Cheers.

3 years later