Learn adding custom nodes for your schematics.

You can add your own nodes for your schematics by simply adding the C# script file to your Unity project.

The Node’s Class

Also, the node’s class must descend from BaseSchematicNode. This, by default, will make it a node with a single Next slot, the connection to the next node is stored in the int field next.

public class NewSchematicNode : BaseSchematicNode

Or, the node’s class can also descend from BaseSchematicCheckNode (which descends from BaseSchematicNode). This is a node with a Success and a Failed slot – the Success connection is stored in the int field next, the Failed connection is stored in the int field nextFail.

public class NewSchematicNode : BaseSchematicCheckNode

Information Attributes

You need to let the editor know some details about the node. this is handled by adding attributes above the class.

[EditorHelp("Node Name", "The description of your node.", "")]
[NodeInfo("Section")]
public class NewSchematicNode : BaseSchematicNode

EditorHelp

The EditorHelp attribute is used for the help text of the node and the node’s title/name. The 1st string parameter defines the name, the 2nd defines the description. The 3rd string parameter is currently unused, but must be added.

NodeInfo

The NodeInfo attribute is used to define where the node will be added in the add node selection.

You can add the node to sub-sections by separating them with a / – and you can add multiple sections where the node should be added by using multiple string parameters. E.g.:

[NodeInfo("Section")]

This will place the node in Add > Section.

[NodeInfo("Section/Sub-Section")]

This will place the node in Add > Section > Sub-Section.

[NodeInfo("Section A", "Section B")]

This will place the node in Add > Section A and Add > Section B.

Editor Functions

Additionally to the attributes, there are functions that should be implemented in your node to tell the editor the info text and color of the node.

// INFO: This returns the text displayed in the node's info area.
public override string GetNodeDetails()
{
	return "Node info text";
}

// INFO: This property handles the color of your node in the node editor.
public override Color EditorColor
{
	get{ return Maki.EditorSettings.baseNodeColor;}
}

The GetNodeDetails function returns the text that is displayed in the node’s info area. The EditorColor property returns the color that is used to tint the node in the editor.

Additionally, you can create multi-slot nodes by overriding the next slot functions. See the BaseSchematicCheckNode for example:

public override string GetNextName(int index)
{
	if(index == 0)
	{
		return "Success";
	}
	else if(index == 1)
	{
		return "Failed";
	}
	return "";
}

public override int GetNextCount()
{
	return 2;
}

public override int GetNext(int index)
{
	if(index == 0)
	{
		return this.next;
	}
	else if(index == 1)
	{
		return this.nextFail;
	}
	return -1;
}

public override void SetNext(int index, int next)
{
	if(index == 0)
	{
		this.next = next;
	}
	else if(index == 1)
	{
		this.nextFail = next;
	}
}

Node Execution

Finally, the most crucial part of the node is the Execute function, which will be used when the node is executed by the schematic. This function will handle whatever you want to do with your node – and it must tell the schematic which node will be executed next.

// INFO: This code will be executed when the node is executed.
public override void Execute(Schematic schematic)
{
	// INFO: Don't forget to tell the schematic what to do next.
	schematic.NodeFinished(this.next);
}

You can also execute the next node after a wait time by using the StartTime function of the schematic:

schematic.StartTime(5.0f, this.next);

The 1st parameter is a float that defines the time in seconds until executing the next node, the 2nd parameter defines the next node’s index (int).

Example

In total, a node class can look like this:

using UnityEngine;
using Makinom;
using System.Collections.Generic;

namespace Makinom.Schematics.Nodes
{
	// INFO: The 'EditorHelp' attribute manages the name and description of the node.
	[EditorHelp("Node Name", "The description of your node.", "")]
	// INFO: The 'NodeInfo' attribute manages in which section the node can be found in the add node selection.
	[NodeInfo("Section")]
	public class NewSchematicNode : BaseSchematicNode
	{
		// INFO: Place your settings here.
		
		public NewSchematicNode()
		{
			
		}
		
		// INFO: This code will be executed when the node is executed.
		public override void Execute(Schematic schematic)
		{
			// INFO: Don't forget to tell the schematic what to do next.
			schematic.NodeFinished(this.next);
		}
		
		
		// INFO: This returns the text displayed in the node's info area.
		public override string GetNodeDetails()
		{
			return "Node info text";
		}
		
		// INFO: This property handles the color of your node in the node editor.
		public override Color EditorColor
		{
			get{ return Maki.EditorSettings.baseNodeColor;}
		}
	}
}

This node doesn’t do much, though. You can add your settings in the class and do whatever needs to be done in the Execute function.

Please note that your custom node doesn’t need to be in the Makinom.Schematics.Nodes namespace, it can be placed in any namespace (or none at all).