Callable is a built-in Variant type that represents a function. It can either be a method within an Object instance, or a standalone function not related to any object, like a lambda function. Like all Variant types, it can be stored in variables and passed to other functions. It is most commonly used for signal callbacks.
Example:
In GDScript, it's possible to create lambda functions within a method. Lambda functions are custom callables that are not associated with an Object instance. Optionally, lambda functions can also be named. The name will be displayed in the debugger, or when calling get_method.
Constructs an empty Callable, with no object nor method bound.
Constructs a Callable as a copy of the given Callable.
Creates a new Callable for the method named method
in the specified object
.
Returns true
if both Callables invoke different targets.
Returns true
if both Callables invoke the same custom target.
Returns a copy of this Callable with one or more arguments bound. When called, the bound arguments are passed after the arguments supplied by call. See also unbind.
Note: When this method is chained with other similar methods, the order in which the argument list is modified is read from right to left.
Returns a copy of this Callable with one or more arguments bound, reading them from an array. When called, the bound arguments are passed after the arguments supplied by call. See also unbind.
Note: When this method is chained with other similar methods, the order in which the argument list is modified is read from right to left.
Calls the method represented by this Callable. Arguments can be passed and should match the method's signature.
Calls the method represented by this Callable in deferred mode, i.e. at the end of the current frame. Arguments can be passed and should match the method's signature.
See also Object.call_deferred.
Calls the method represented by this Callable. Unlike call, this method expects all arguments to be contained inside the arguments
Array.
Return the bound arguments (as long as get_bound_arguments_count is greater than zero), or empty (if get_bound_arguments_count is less than or equal to zero).
Returns the total amount of arguments bound (or unbound) via successive bind or unbind calls. If the amount of arguments unbound is greater than the ones bound, this function returns a value less than zero.
Returns the name of the method represented by this Callable. If the callable is a GDScript lambda function, returns the function's name or "<anonymous lambda>"
.
Returns the object on which this Callable is called.
Returns the ID of this Callable's object (see Object.get_instance_id).
Returns the 32-bit hash value of this Callable's object.
Note: Callables with equal content will always produce identical hash values. However, the reverse is not true. Returning identical hash values does not imply the callables are equal, because different callables can have identical hash values due to hash collisions. The engine uses a 32-bit hash algorithm for hash.
Returns true
if this Callable is a custom callable. Custom callables are created from bind or unbind. In GDScript, lambda functions are also custom callables.
Returns true
if this Callable has no target to call the method on.
Returns true
if this Callable is a standard callable. This method is the opposite of is_custom. Returns false
if this callable is a lambda function.
Returns true
if the callable's object exists and has a valid method name assigned, or is a custom callable.
Perform an RPC (Remote Procedure Call) on all connected peers. This is used for multiplayer and is normally not available, unless the function being called has been marked as RPC (using @GDScript.@rpc or Node.rpc_config). Calling this method on unsupported functions will result in an error. See Node.rpc.
Perform an RPC (Remote Procedure Call) on a specific peer ID (see multiplayer documentation for reference). This is used for multiplayer and is normally not available unless the function being called has been marked as RPC (using @GDScript.@rpc or Node.rpc_config). Calling this method on unsupported functions will result in an error. See Node.rpc_id.
Returns a copy of this Callable with a number of arguments unbound. In other words, when the new callable is called the last few arguments supplied by the user are ignored, according to argcount
. The remaining arguments are passed to the callable. This allows to use the original callable in a context that attempts to pass more arguments than this callable can handle, e.g. a signal with a fixed number of arguments. See also bind.
Note: When this method is chained with other similar methods, the order in which the argument list is modified is read from right to left.