Node

You are here:
< All Topics
Table of Contents
Add code

Your code which is going to be executed by your node should be inside of the OnExecute method.

Good to know

You can edit a node script by simply right-click on the node and select edit script. This is also a great way to examine existing nodes.

Example:

//
// Execute a simple Debug.Log() command.
public override void OnExecute(FlowReactorComponent _flowReactor)
{
// Execute
Debug.Log("Hello World");
}
//
Call next node:

After your node has finished with its code it’s important to call the next connected node. You can do this by calling ExecuteNext.

Example:

//
public override void OnExecute(FlowReactorComponent _flowReactor)
{
// Execute
Debug.Log("Hello World");

// Execute next node connected to output index 0
ExecuteNext( 0, _flowReactor );
}
//

Alternative:


enum CustomOutputs
{
    OutputA = 0,
    OutputB = 1
}
//

public override void OnExecute(FlowReactorComponent _flowReactor)
{
// Execute
Debug.Log("Hello World");

// Execute next node with custom enum selection
ExecuteNext(CustomOutputs.OutputA, _flowreactor);
}
//
Virtual Methods

A node has several virtual methods which can be overriden
see all methods on the right:

// The initial method is being called on node creation in editor
public virtual void Init(Graph _graph, Node _node){}

public virtual void DrawCustomInspector(){}

public virtual void DrawGUI(string _title, int _id, Graph _graph, GUISkin _editorSkin){}

// Execute the actual code
public virtual void OnExecute(FlowReactorComponent _flowReactor){}

// Execute the node, only available if node is type of coroutine node
public virtual IEnumerator OnExecuteCoroutine(FlowReactorComponent _flowReactor) { yield break; }

// Similar to the Monobehaviour Awake.
// Gets called on initialization on every node in all graphs and subgraphs.
// (No matter if the sub-graph is currently active or not)
public virtual void OnInitialize(FlowReactorComponent _flowRector){}

// OnGraphStart should be only used by the OnStart node.
// Unlike the OnInitialization, OnGraphStart only gets called in the root graph and only if the graph is active.
public virtual void OnGraphStart(FlowReactorComponent _flowReactor){}

// Similar to the Monobehaviour Update method. Gets called on every frame.
public virtual void OnUpdate(FlowReactorComponent _flowReactor){}

public virtual void OnLateUpdate(FlowReactorComponent _flowReactor){}

public virtual void OnFixedUpdate(FlowReactorComponent _flowReactor){}

public virtual void OnApplicationExit(FlowReactorComponent _flowReactor){}

// Editor method which gets called when the node has been selected.
public virtual void OnSelect(Graph _graph){}

public virtual void OnDelete(){}
Variable Attributes

Variable attributes are a great way to decorate your custom FRVariables in your node so you can easily add additional informations which will show up in the node inspector.

// Show a title above the variable field
[Title("Title")]

// Show a helpbox message
[HelpBox("Message", HelpBox.MessageType)]

// Show a button with custom title. On click it will open the url
[OpenURL("Title", "URL")]

// Hide a variable in the inspector
[Hide]

// Hide a variable in the node field
[HideInNode]

// Group variables
[VariableGroup("GroupName")]

Example:

Custom node inspector

Additionally to the variable attributes it is possible to create a complete custom node inspector with specific editor gui layout elements. Many FlowReactor nodes have custom inspectors. For example the Get and Set Property nodes have a custom inspector with a drag and drop area or the ShowDialog node.

To create a custom node inspector simple override the OnDrawCustomInspector method and add your GUI Elements.

Warning

If you’re using EditorGUILayout elements please make sure to set them inside of #If UNITY_EDITOR / #endif 

Example:

//
// Example for a custom node inspector
// Draw a simple GUI Label
//
public override void DrawCustomInspector()
{
GUILayout.Label("Custom Title");
}
AddOutput / RemoveOutput

FlowReactor provides you with two simple methods to add and remove outputs on custom nodes.
Simply call
AddOutput(string outputName);
to add a new output or 
RemoveOutput(int outputIndex);
to remove an output

Example:


// Adds a simple gui button to the node inspector. On click it adds a new output to the node
#if UNITY_EDITOR
public override void DrawCustomInspector()
{
if (GUILayout.Button("Add Output"))
{
AddOutput("");
}
}
#endif
Privacy Settings
We use cookies to enhance your experience while using our website. If you are using our Services via a browser you can restrict, block or remove cookies through your web browser settings. We also use content and scripts from third parties that may use tracking technologies. You can selectively provide your consent below to allow such third party embeds. For complete information about the cookies we use, data we collect and how we process them, please check our Privacy Policy
Youtube
Consent to display content from Youtube
Vimeo
Consent to display content from Vimeo
Google Maps
Consent to display content from Google