How to stop a running SubGraph?



As shown in Figure 1, in Debug mode, the SubGraph node is always running. How do I stop this SubGraph?
The Action node in SubGraph is a custom node. The code is as shown below:

public partial class RotateTransformAction : Action
{
    [SerializeReference] public BlackboardVariable<Transform> Transform;
    [SerializeReference] public BlackboardVariable<Vector3> Axis;
    [SerializeReference] public BlackboardVariable<float> Angle;

    protected override Status OnStart()
    {
        if (!Transform.Value)
        {
            return Status.Failure;
        }

        Transform.Value.Rotate(Axis.Value, Angle.Value * Time.deltaTime);

        return Status.Running;
    }

    protected override Status OnUpdate()
    {
        return Status.Success;
    }

    protected override void OnEnd()
    {
    }
}

Hi @godblesschimp

From a quick look I’d would say it is caused by your RotateGraph On Start node having the Repeat value to true.

1 Like

You reminded me and I found the problem. I made the following changes:

  1. SubGraph’s OnStart.Repeat=False
  2. Added a duration parameter During to the rotation custom node to control the end of the node
  3. Transferred the specific method of rotation from the OnStart function to the OnUpdate function
    Now the main graph and the subgraph can correctly complete my idea, that is, the main graph executes the subgraph in some way, and the subgraph returns the node status correctly after the execution is completed.

public partial class RotateTransformAction : Action
{
    [SerializeReference] public BlackboardVariable<Transform> Target;
    [SerializeReference] public BlackboardVariable<Vector3> Axis;
    [SerializeReference] public BlackboardVariable<float> Angle;
    [SerializeReference] public BlackboardVariable<float> During;

    protected override Status OnStart()
    {
        if (!Target.Value || During.Value < 0)
        {
            return Status.Failure;
        }

        if (During.Value == 0)
        {
            return Status.Success;
        }

        return Status.Running;
    }

    protected override Status OnUpdate()
    {
        Target.Value.Rotate(Axis.Value, Angle.Value * Time.deltaTime);

        During.Value -= Time.deltaTime;
        if (During.Value <= 0)
        {
            return Status.Success;
        }

        return Status.Running;
    }

    protected override void OnEnd()
    {
        During.Value = 0;
    }
}
1 Like

I didn’t realize your node was relying on the repeat of the On Start node.
You’ve improve your node to fit your use case, glad it helps :slightly_smiling_face: