Using Generics

Using generic functions

One of the most using generic functions is GetComponent<T>, where T is a generic type parameter which defines a type of component which is required:

Generic parameter type can be selected from dropdown list by pressing generic parameter button on top of node. After that the out pin of node will return component of defined type.


Using generic variables

Generic types can be holder or collection of defined variable type. 

Example (Generic collections): 


Create List<T> variable:

Define the generic <T> parameter as a string:

Now List<string> is a dynamic collection of string objects.

Check option to initialize variable, otherwise it will be “null” and will cause “NullReferenceException” error:

Adding new objects to collection.

Find method “Add” from dragging out pin of variable with “Equal type” option is enabled. Owner class must be List<T>:

After creation node it will be linked with this function node and its generic type will be automatically defined as “string”.

Connect node with sequence connector and define new adding item name:

Add few new objects to collection in same way and connect it to “Foreach loop” node. It will iterate through all objects of collection and we can print to console all values (with default node "Print ot console"):

Render time: 0.01 seconds
136,985 unique visits