I ran into this because of my lack of knowledge, but now that I (think) I understand what’s going on, I wanted to clarify the use cases behind the buttons mentioned in the title.
My situation was the following: I created a custom scene - a HBoxContainer with a couple of controls as it’s children, added using the editor. Lets call this scene SceneChild. I then wanted to add that to another custom scene. Lets call this scene SceneParent. At this point, I didn’t even know what the “Instantiate Child Scene” is for, so I tried finding it in the “Add Child Node” menu, didn’t find it, added class_name to SceneChild’s script and viola - it appeared and I used it to add SceneShild as a child of SceneParent. When I tried running the SceneParent scene, it turns out I can’t access any of the children in SceneChild from it’s own script because none of them get created and added as children. On the other hand, running just the SceneChild worked fine and the children were found without issues. Once I removed the added children in the editor and added them back using “Instantiate Child Scene”, everything was fine.
After some research on the web and this forum (I couldn’t find anything about this in the docs), my understanding now is that “Instantiate Child Scene” will instantiate the packed scene from the .tscn file (along with it’s children), but “Add Child Node” only creates the node, without instantiating and adding the children (which, it seems to me, only makes sense for built-in nodes and nodes/scenes that have all of their children added through code).
My questions are:
Is my conclusion correct? Am I missing any subtle details?
Is there a use case for using “Add Child Node” for custom scenes with children added through the editor (i.e. not through code)? If not, it looks to me like godot is not just allowing the user to shoot himself in the foot, but providing the shotgun as well. Also, if there’s a something that explains this properly in the docs, I’d appreciate the link.
Yes your conclusion is correct. “add child node” only adds the class_script to the scene, while “instantiate child scene” instances a scene. In code the differences would be these:
Both ways have their usefullness eventhough you are right most of the time you would use the first method for built-in nodes while the second method is most of the times used for your own scenes.
I use the first method a lot though for my own scripts which dont have children
@herrspaten Thanks for the info and for confirming my understanding.
I might make a suggestion somewhere to do something about this. I understand that there are valid use cases for most of these combinations, but some still seem to me like an invitation for a bug and nothing else. I think these need to be either prevented or at least much better documented. As far as I could see, I’m not the first guy running into this issue either.
I dont agree with preventing this from happening, but i understand that maybe some better documentation inside the engine would be helpful for beginners. These both have their usecases and i personally never use the instantiate child scene
-button. Instead i just drag my scenes from the filer-manager in the scene
This stuff is covered in some detail, in both docs and the tutorials. Creating, adding, removing, getting and sharing nodes is all pretty much the first thing you have to learn.
As an example:
And a tutorial:
And many more:
I think the docs go beyond being just docs, which is why they are so good. With tutorials, extended explanations, many worked examples. Of course anything can be improved, if you did have an improvement in mind you can always contribute of course. Even the docs on contributing are pretty thorough too.
While I agree that the docs are very good, I don’t think this subtlety is covered well there. I’ve read all the pages you posted and I invested a couple of hours into going through the docs trying to find this info before posting here (and at that point, I knew what I was trying to find too!). I also only ran into this problem a couple months into my project and never encountered it before. I don’t know, maybe I misunderstood the docs?
I also think that the distinction between a node, a class, a script a scene etc. is a bit complicated in Godot (but it is documented, even though the explanation is a bit scattered throughout the docs). In light of that, I think adding an explanation about this in the docs is still valuable.
I’ll see how to go about this. I’ll try making a suggestion through appropriate channels and make the contribution (if they can point me to the best place in the docs for it).
Well fair enough and well said. I have never contributed but I have only been using Godot for a short time too and still feel like a beginner.
Nodes are classes, just built in ones. Scripts are resources and a scene is a collection or tree of nodes. Although this stuff is scattered around a bit, you may be right that some clarification or perhaps an extra page in the intro somewhere may be a good idea.