A method (function) is a code block that contains a series of statements (nodes) which will be executed when function will be invoked.

Read Node edit graph for more information about entry&return nodes, links between nodes and how to use sequence and data nodes.

Creating function

The functions can be created by pressing ‘plus’ button on Functions section:


Adding pins

Each function can be invokes with a set of arguments (inputs), which allow to transfer some data (variables) inside function. To add new parameters to function press ‘New’ button in ‘Inputs’ section of function Details window. Each argument will have own name and type. Arguments with the same name are not allowed.

After adding the inputs to our function it can be executed with arguments:

If the function must return some data you can add out pin by ‘New’ button in ‘Outputs’ section of function Details window:

Now the function can return a value or can be executed by sequence connector as simple function:


Ref/Out parameters

If the function is outside of a class and you need to return more than value from function you can use the ‘ref’ and ‘out’ parameters of arguments. The ‘ref’ parameter causes an argument to be passed by reference, not by value (the value will be returned to a variable that connected to this). The ‘out’ parameter is the same, but the value must be set before function finish executing code and exit.

To set the value of ‘ref’ or ‘out’ parameter use ‘Set value’ node:

(in this screenshot used the ‘Conditional expression’ node, which identifies which value to return based on bool condition)


Now our function can return a value to a variable that connected to argument with ‘ref’ parameter:


Function modifiers 

public - access is not restricted.

private - access is limited to the containing type.


static modifier is used to declare a static member, which belongs to the type itself rather than to a specific object. That means the public static function can be executed from type directly:

 and not required a instance of class as public non-static function which shown on screenshot below:

Note: you can’t use non-static variables in static function.


The virtual modifier is used to modify a method and allow for it to be overridden in a derived class. It means that you can create a class ‘A’ with a virtual function and you will be able to override the code of this function in class ‘B’ which derived from class ‘A’.


Other modifiers:

protected - access is limited to the containing class or types derived from the containing class.

internal - access is limited to the current assembly.

protected internal - access is limited to the current assembly or types derived from the containing class.



Function attributes

Function attributes can be used to sign this function for some functionality. To add attribute to a variable press ‘plus’ button in Attribute section and select it from list.

For example the most used function attribute is ‘MenuItem’. It used on static functions in class that derived from ‘EditorWindow’ class to notify unity editor which function to execute to open editor window.

Render time: 0.01 seconds
136,987 unique visits