IReleaseReceiver

You can implement a method to be called when the graph is released.
Please note that for Logic Graphs, this is called when the graph object is destroyed, regardless of the playback status of the graph.
Please note that for Function Graphs, this is called every time playback ends, even if you run the same function graph repeatedly on the same node.

How to write a script

  • Implement LogicToolkit.IReleaseReceiver in types that inherit from various NodeComponent.
  • Implement public void OnRelease().

Code example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LogicToolkit;

[System.Serializable]
public class ReleaseExample : ActionComponent, IReleaseReceiver
{
    [SerializeField]
    private GameObject prefab;

    [SerializeField]
    private OutputDataPort<GameObject> output;

    private GameObject instance;

    protected override void OnAction()
    {
        if (instance == null)
        {
            instance = Object.Instantiate(prefab);
        }

        output.SetValue(instance);
    }

    public void OnRelease()
    {
        if (instance != null)
        {
            Object.Destroy(instance);
            instance = null;
        }
    }
}

In this example, we instantiate the prefab once at runtime and destroy the instantiated object on release.