Learn starting a schematic in your code.

You can start a schematic in your custom scripts without having to use a machine component.

Loading from a Schematic Asset

Before a schematic can be started, you need to load it from a schematic asset.

You can e.g. add it as a field in your component.

public MakinomSchematicAsset schematicAsset;

Use this code to load the schematic asset into an actual schematic.

Schematic schematic = new Schematic(this.schematicAsset);

Starting a schematic

You can either start the schematic with or without priority through one of the PlaySchematic functions.

Non-Priority Start

Let’s take a look at the function to start without priority first:

public void PlaySchematic(IExecutionStarter starter, 
	GameObject machineObject, GameObject startingObject, 
	bool isBlocking, MachineUpdateType updateType)
  • IExecutionStarter starter
    The IExecutionStarter interface used as an argument will be notified by the schematic when it finished playing.
    Implement the IExecutionStarter interface in a class (e.g. the class starting the schematic), or just use null as an argument to not get notified.
  • GameObject machineObject
    The game object that will be used as machine object in the schematic.
  • GameObject startingObject
    The game object that will be used as starting object in the schematic.
  • bool isBlocking
    Use true if this is a blocking schematic, otherwise false.
    Only one blocking schematic can be executed at a time.
  • MachineUpdateType updateType
    The MachineUpdateType enum handles which update function (UpdateLateUpdate or FixedUpdate) will be used by the schematic.

A call of this function can look like this.

schematic.PlaySchematic(null, machineObject, startObject, false, MachineUpdateType.Update);

Priority Start

Starting a schematic with priority is also done through the PlaySchematic function, using one additional parameter:

public void PlaySchematic(int priority, IExecutionStarter starter, 
	GameObject machinObject, GameObject startingObject, 
	bool isBlocking, MachineUpdateType updateType)
  • int priority
    The priority of the schematic.
    The highest priority number will be executed first.

The rest of the parameters are the same as using the non-priority start function.

A call of this function can look like this.

schematic.PlaySchematic(10, null, machineObject, startObject, false, MachineUpdateType.Update);

The IExecutionStarter Interface

If you want to be notified by a schematic when it finished playing, implement the IExecutionStarter interface in your class. The interface will add 2 functions and 2 properties to the class.

An example implementation in a component can look like this.

public GameObject GameObject
{
	get{ return this.gameObject;}
}

public bool Enabled
{
	get
	{
		return this.enabled && this.gameObject.activeInHierarchy;
	}
}

public void ExecutionEnded(GameObject startingObject)
{
	// the schematic finished playing
}

public void DontDestroy()
{
	GameObject.DontDestroyOnLoad(this.gameObject);
}