0 votes


I'm fairly new to the Godot world and I do understand that this might not be the most efficient or "proper" way of doing things, but I like to do things in one place and please excuse me.

How do I assign child node's _ready function from the parent node's script?

I did try

MyObjet.set("_ready", custom_ready_funcref)

didn't work.

Godot version 3.5.1
in Engine by (15 points)

1 Answer

+1 vote
Best answer

If you only need to do something with a child node's _ready() function, attach a script to the child node (if you can attach it in the editor, and not trying to do this at runtime), and write the code in the child node's _ready() function.

If it's something more complicated, then please explain the problem a bit more.

by (3,162 points)
selected by

I'm creating nodes using .new method in parent object's _init method. This function must be executed at run time, doesn't it?! I think what I'm trying do to is not exactly possible, I'm generating objects on the fly and trying to assign overrides of virtual initialization and processing functions at run time...

If these are classes such that the _init() function is being used, then figure out which properties of the class must be defined outside of the class, and add them as parameters to the _init() function:

class Foo:
    var thing1
    var thing2
    func _init(item1, item2):
        var thing1 = item1
        var thing2 = item2

Then when it comes time to assign an object, fill in the necessary data:

var bar = Foo.new("I'm Thing 1!", "I'm Thing 2!")

Note that this is only when making a class. Regular ol' GDScript with a node that extends another node doesn't require the _init() function to be defined. Hope that helps.

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.