Godot Errors and solutions
In this read I have listed the error and bugs I face while making godot projects (This is not connected to any specific to one project)
Table of content
- Child class sub-node is not ready with @onready
/ _ready
function.
The child class sub-node is not ready on _ready/@onready
when making a new instance of the class
Problem: when creating the new instance of the class (Custom class <node>) its children are not being added to the property.
Solution: to have @onready
variables or code from _ready
function creating a class of that node is not a good idea it turns out you would have to create a new instance of that packed scene.
Discussion: code with the issue can be found in tmp
folder of this repo
What I had in my mind was creating a class of root node of a scene and if I create a new instance of that class then the whole scene would be recreated.
That's where I am wrong, By making a custom class I am just adding some additional functionality on the existing base class, the class which that node initially extends from, meaning I can add some extra property in the base class but expecting that my custom class would carry whole scene is asking too much, it would just carry additional property of the base class, not his children with it for this a packed scene has to be used. also, I think when we use new()
function it calls _init()
the function of the node whereas, using instantiate()
would call _ready()
function.
Resolve repo: de22b8a