:github_url: hide .. DO NOT EDIT THIS FILE!!! .. Generated automatically from Godot engine sources. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/Callable.xml. .. _class_Callable: Callable ======== An object representing a method in a certain object that can be called. Description ----------- ``Callable`` is a first class object which can be held in variables and passed to functions. It represents a given method in an :ref:`Object`, and is typically used for signal callbacks. \ **Example:**\ .. tabs:: .. code-tab:: gdscript func print_args(arg1, arg2, arg3 = ""): prints(arg1, arg2, arg3) func test(): var callable = Callable(self, "print_args") callable.call("hello", "world") # Prints "hello world ". callable.call(Vector2.UP, 42, callable) # Prints "(0, -1) 42 Node(Node.gd)::print_args". callable.call("invalid") # Invalid call, should have at least 2 arguments. .. code-tab:: csharp public void PrintArgs(object arg1, object arg2, object arg3 = null) { GD.PrintS(arg1, arg2, arg3); } public void Test() { Callable callable = new Callable(this, nameof(PrintArgs)); callable.Call("hello", "world"); // Prints "hello world null". callable.Call(Vector2.Up, 42, callable); // Prints "(0, -1) 42 Node(Node.cs)::PrintArgs". callable.Call("invalid"); // Invalid call, should have at least 2 arguments. } Constructors ------------ +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Callable` | :ref:`Callable` **(** **)** | +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Callable` | :ref:`Callable` **(** :ref:`Callable` from **)** | +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+ | :ref:`Callable` | :ref:`Callable` **(** :ref:`Object` object, :ref:`StringName` method **)** | +---------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+ Methods ------- +-------------------------------------+-------------------------------------------------------------------------------------------------------------+ | :ref:`Callable` | :ref:`bind` **(** ... **)** |vararg| |const| | +-------------------------------------+-------------------------------------------------------------------------------------------------------------+ | :ref:`Variant` | :ref:`call` **(** ... **)** |vararg| |const| | +-------------------------------------+-------------------------------------------------------------------------------------------------------------+ | void | :ref:`call_deferred` **(** ... **)** |vararg| |const| | +-------------------------------------+-------------------------------------------------------------------------------------------------------------+ | :ref:`StringName` | :ref:`get_method` **(** **)** |const| | +-------------------------------------+-------------------------------------------------------------------------------------------------------------+ | :ref:`Object` | :ref:`get_object` **(** **)** |const| | +-------------------------------------+-------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`get_object_id` **(** **)** |const| | +-------------------------------------+-------------------------------------------------------------------------------------------------------------+ | :ref:`int` | :ref:`hash` **(** **)** |const| | +-------------------------------------+-------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_custom` **(** **)** |const| | +-------------------------------------+-------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_null` **(** **)** |const| | +-------------------------------------+-------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_standard` **(** **)** |const| | +-------------------------------------+-------------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`is_valid` **(** **)** |const| | +-------------------------------------+-------------------------------------------------------------------------------------------------------------+ | void | :ref:`rpc` **(** ... **)** |vararg| |const| | +-------------------------------------+-------------------------------------------------------------------------------------------------------------+ | void | :ref:`rpc_id` **(** :ref:`int` peer_id, ... **)** |vararg| |const| | +-------------------------------------+-------------------------------------------------------------------------------------------------------------+ | :ref:`Callable` | :ref:`unbind` **(** :ref:`int` argcount **)** |const| | +-------------------------------------+-------------------------------------------------------------------------------------------------------------+ Operators --------- +-------------------------+--------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`operator !=` **(** :ref:`Callable` right **)** | +-------------------------+--------------------------------------------------------------------------------------------------------+ | :ref:`bool` | :ref:`operator ==` **(** :ref:`Callable` right **)** | +-------------------------+--------------------------------------------------------------------------------------------------------+ Constructor Descriptions ------------------------ .. _class_Callable_constructor_Callable: - :ref:`Callable` **Callable** **(** **)** Constructs a null ``Callable`` with no object nor method bound. ---- - :ref:`Callable` **Callable** **(** :ref:`Callable` from **)** Constructs a ``Callable`` as a copy of the given ``Callable``. ---- - :ref:`Callable` **Callable** **(** :ref:`Object` object, :ref:`StringName` method **)** Creates a new ``Callable`` for the method called ``method`` in the specified ``object``. Method Descriptions ------------------- .. _class_Callable_method_bind: - :ref:`Callable` **bind** **(** ... **)** |vararg| |const| Returns a copy of this ``Callable`` with the arguments bound. Bound arguments are passed after the arguments supplied by :ref:`call`. ---- .. _class_Callable_method_call: - :ref:`Variant` **call** **(** ... **)** |vararg| |const| Calls the method represented by this ``Callable``. Arguments can be passed and should match the method's signature. ---- .. _class_Callable_method_call_deferred: - void **call_deferred** **(** ... **)** |vararg| |const| Calls the method represented by this ``Callable`` in deferred mode, i.e. during the idle frame. Arguments can be passed and should match the method's signature. ---- .. _class_Callable_method_get_method: - :ref:`StringName` **get_method** **(** **)** |const| Returns the name of the method represented by this ``Callable``. ---- .. _class_Callable_method_get_object: - :ref:`Object` **get_object** **(** **)** |const| Returns the object on which this ``Callable`` is called. ---- .. _class_Callable_method_get_object_id: - :ref:`int` **get_object_id** **(** **)** |const| Returns the ID of this ``Callable``'s object (see :ref:`Object.get_instance_id`). ---- .. _class_Callable_method_hash: - :ref:`int` **hash** **(** **)** |const| Returns the 32-bit hash value of this ``Callable``'s object. \ **Note:** ``Callable``\ s 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 :ref:`hash`. ---- .. _class_Callable_method_is_custom: - :ref:`bool` **is_custom** **(** **)** |const| Returns ``true`` if this ``Callable`` is a custom callable whose behavior differs based on implementation details. Custom callables are used in the engine for various reasons. If ``true``, you can't use :ref:`get_method`. ---- .. _class_Callable_method_is_null: - :ref:`bool` **is_null** **(** **)** |const| Returns ``true`` if this ``Callable`` has no target to call the method on. ---- .. _class_Callable_method_is_standard: - :ref:`bool` **is_standard** **(** **)** |const| Returns ``true`` if this ``Callable`` is a standard callable, referencing an object and a method using a :ref:`StringName`. ---- .. _class_Callable_method_is_valid: - :ref:`bool` **is_valid** **(** **)** |const| Returns ``true`` if the object exists and has a valid function assigned, or is a custom callable. ---- .. _class_Callable_method_rpc: - void **rpc** **(** ... **)** |vararg| |const| Perform an RPC (Remote Procedure Call). This is used for multiplayer and is normally not available unless the function being called has been marked as *RPC*. Calling it on unsupported functions will result in an error. ---- .. _class_Callable_method_rpc_id: - void **rpc_id** **(** :ref:`int` peer_id, ... **)** |vararg| |const| 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*. Calling it on unsupported functions will result in an error. ---- .. _class_Callable_method_unbind: - :ref:`Callable` **unbind** **(** :ref:`int` argcount **)** |const| Returns a copy of this ``Callable`` with the arguments unbound. Calling the returned ``Callable`` will call the method without the extra arguments that are supplied in the ``Callable`` on which you are calling this method. Operator Descriptions --------------------- .. _class_Callable_operator_neq_bool: - :ref:`bool` **operator !=** **(** :ref:`Callable` right **)** Returns ``true`` if both ``Callable``\ s invoke different targets. ---- .. _class_Callable_operator_eq_bool: - :ref:`bool` **operator ==** **(** :ref:`Callable` right **)** Returns ``true`` if both ``Callable``\ s invoke the same custom target. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)` .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)` .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)` .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)` .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)` .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`