+2 votes

In the documentation it says:


Description: In GDScript, functions are not first-class objects. This means it is impossible to store them directly as variables, return them from another function, or pass them as arguments.
However, by creating a FuncRef using the @GDScript.funcref function, a reference to a function in a given object can be created, passed around and called.

I didn't understood. It's like editing functions on the fly or passing functions as an argument?

in Engine by (375 points)

1 Answer

+8 votes
Best answer

It allows to store a function into a single variable, so that only this variable will be required to call it on the proper object. It can then be passed as a single argument to other functions as well.
It is not "editing" functions, just passing them around.


obj.say_hello("message", 42)

Is the same as:

var f = funcref(obj, "say_hello")
f.call_func("message", 42)
by (29,042 points)
selected by
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.