# IStopReceiver

You can implement a method to be called when the graph is stopped.
Please note that for function graphs, this is called when the function graph itself is stopped, regardless of the playback status of the parent graph.

## How to write a script

- Implement `LogicToolkit.IStopReceiver` in types that inherit from various NodeComponents.
- Implement `public void OnStop()`.

## 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 StopExample : ActionComponent, IStopReceiver
    {
        [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 OnStop()
        {
            if (instance != null)
            {
                Object.Destroy(instance);
                instance = null;
            }
        }
    }

In this example, we instantiate the prefab once at run time and destroy the instantiated object when we stop.