A delegate is a type that represents references to methods with a particular parameter list and return type. When you instantiate a delegate, you can associate its instance with any method with a compatible signature and return type. You can invoke (or call) the method through the delegate instance.


Creating delegates

To create new delegate press ‘plus’ button on the right side of Delegates section:

Note: If you can't find this section, check its visibility in the panel 'Hidden script objects' in the bottom of toolbar.

If you associate this delegate with function that has arguments or return type you can set these arguments or return type in Details window of this delegate:


Using delegates

After compiling script you will able to use this delegate as variable type:

Don’t forget to initialize the start value, otherwise executing of null delegate variable will cause en error.


To assign function to a delegate just link it with special pin at the corner of the function node:


Also you can add other links to this delegate (multidelegate) using ‘Increment/Decrement node’ with operation “+=”, and when delegate will be executed all the functions which assigned to this delegate will be executed too:

Note: executing functions with delegates faster than direct function execution.

You can remove your functions from delegate by using the same ‘Increment/Decrement node’ node but changing operation to “-=”.


Also you can make a code and assign it to delegate with the ‘Make delegate’ node:



Executing delegates

To execute method find ‘Invoke’ method from delegate variable. Invoking delegate cause executing all code and functions in delegate.

Render time: 0.02 seconds
136,990 unique visits