This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

So to give a quick brief of what I thought of doing:
I have a base scene, exporting attributes pertaining a certain type of situation, this base will be inherited by several others, filling in the attributes with content where due, good design right?

I'm going to use a resourcePreloader to pipe the loading process of everything and the depending resources. Then when needed, the running game scene can just call from the storage and child it on the tree. I am however unsure if I should store these scenes as PackedScenes or instanced versions of it, because of two key aspects:

  1. whether or not entertree is sent upon instancing or upon entering the working tree, added as a child to main viewport, this is important to know when the processes will take place, as it will need a creating phase, and a showing phase.

  2. it may be needed to make alterations to the scene while on storage, change of the exported attributes, it may be the case that you can't do that on PackedScenes, its a different question but related to the above.

Thanks, any other insightful suggestion to the above use case is also welcomed.

in Engine by (61 points)

1 Answer

+2 votes

_init() is called upon instancing. It's something like a constructor.
_enter_tree() is called after node is added to SceneTree and before its children are.
_ready() is called after both node and its children are added to SceneTree.
_exit_tree() is called before node is removed from SceneTree. It's not destructor's equivalent. 'Destructor' in GDscript is this:

func _notification(what):
        # destruction code

One thing to remeber is the node will not have access to SceneTree instance before actually entering it. It can be solved by creating and autoload with function that calls get_tree() but i have no idea if it's a good practice or not.

Hope that helps.

by (2,308 points)

Thanks, I was thinking about this and indeed I forgot about the init function, which should be the proper constructor indeed. The reason for the mess I thinkis the way _entertree is described on the documentation:

Called when the node enters the SceneTree (e.g. upon instancing, scene changing or after calling addchild() in a script). If the node has children, its _entertree() callback will be called first, and then that of the children.

But thanks, I have a better idea on how use each of these now.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.