IInitializeReceiver

You can implement a method to be called when the graph is initialized.
Note that for function graphs, this will be called every time before playback starts, even if you run the same function graph repeatedly on the same node.

How to write a script

  • Implement LogicToolkit.IInitializeReceiver in types that inherit from various NodeComponents.
  • Implement public void OnInitialize().

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

[System.Serializable]
public class InitializeExample : ActionComponent, IInitializeReceiver
{
    private Rigidbody rigidbody;

    [SerializeField]
    private InputField<Vector3> force;

    public void OnInitialize()
    {
        rigidbody = Player.GetComponent<Rigidbody>();
    }

    protected override void OnAction()
    {
        if (rigidbody != null)
        {
            rigidbody.AddForce(force.Value, ForceMode.Impulse);
        }
    }
}

In this example, the Rigidbody component added to the playback object of the graph is obtained in advance at initialization, and a force is applied to the obtained Rigidbody when executed.