Custom Nodes

Learn how to write custom nodes.

Adding custom nodes to schematics or formulas doesn’t require implementing them in a plugin or Makinom’s source code – you can just add them in a script file in your Unity project.

Base Nodes #

Some basics are valid for schematic and formula nodes.

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 can be used for additional information, e.g. a link to a website with more details, it can be omitted.

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 Node > Section.

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

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

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

This will place the node in Add Node > Section A and Add Node > 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 or BaseFormulaCheckNode for examples:

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;
	}
}

Schematic Nodes #

You can create custom nodes by deriving from the BaseSchematicNode or BaseSchematicCheckNode classes. For examples it’s best to check out the available node implementations.

Deriving from BaseSchematicNode 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

Deriving from BaseSchematicCheckNode (which descends from BaseSchematicNode) will make 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

You can also create multi-slot nodes, see above for more details.

Using schematic nodes should use the schematic node namespace.

using GamingIsLove.Makinom.Schematics.Nodes;

Or, implement the node in the namespace (not required).

namespace GamingIsLove.Makinom.Schematics.Nodes

Node Execution #

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 System.Collections.Generic;

namespace GamingIsLove.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 GamingIsLove.Makinom.Schematics.Nodes namespace, it can be placed in any namespace (or none at all).

Formula Nodes #

You can create custom nodes by deriving from the BaseFormulaNode or BaseFormulaCheckNode classes. For examples it’s best to check out the available node implementations.

Deriving from BaseFormulaNode 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 NewFormulaNode : BaseFormulaNode

Deriving from BaseFormulaCheckNode (which descends from BaseFormulaNode) will make 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 NewFormulaNode : BaseFormulaCheckNode

You can also create multi-slot nodes, see above for more details.

Using formula nodes should use the formula node namespace.

using GamingIsLove.Makinom.Formulas.Nodes;

Or, implement the node in the namespace (not required).

namespace GamingIsLove.Makinom.Formulas.Nodes

Node Calculation #

The most crucial part of the node is the Calculate function, which will be used when the node is executed by the formula. This function will handle whatever you want to do with your node – and it must return which node (index) will be executed next.

public override int Calculate(FormulaCall call)
{
	return this.next;
}

To change the current value of the formula, change the call‘s result (float value).

call.result += 1;

The call also has access to user and target of the formula, as well as local variables and selected data.

Example #

In total, a node class can look like this:

using UnityEngine;
using System.Collections.Generic;

namespace GamingIsLove.Makinom.Formulas.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 NewFormulaNode : BaseFormulaNode
	{
		// INFO: Place your settings here.

		public NewFormulaNode()
		{

		}

		// INFO: This code will be executed when the node is executed.
		public override int Calculate(FormulaCall call)
		{
			call.result += 1;
			return 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, it just adds 1 to the result. You can add your settings in the class and do whatever needs to be done in the Calculate function.

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

Tip: Copy existing nodes #

Instead of starting your node from scratch, copy the code of an existing node from the source code and adjust it to your needs.

Base your custom nodes on existing nodes with a similar functionality (or fields you need) to save yourself some time.

Don’t forget to change the name of the class and the content of the EditorHelp attribute.