Forum rules - please read before posting.

How can I check if an ActionList is done running?

I'm writing a Behavior script for some characters that can run actionLists at some points. I'm using actionList.Interact() for that. I would like to implement a way to wait while the ActionList is running. Is there a way to check that directly? Or a way to get the duration of the action list so that I can wait that time?

Comments

  • Depending on need, you can either read the value of actionList.AreActionsRunning() in an Update loop, or hook into the OnEndActionList custom event to run code at the exact moment it ends:

    private void OnEnable () { EventManager.OnEndActionList += OnEndActionList; }
    private void OnDisable () { EventManager.OnEndActionList -= OnEndActionList; }
    
    private void OnEndActionList (ActionList actionList, ActionListAsset actionListAsset, bool isSkipping)
    {
        if (actionList == myActionList)
        {
            //
        }
    }
    
  • AreActionsRunning() seems ideal, but when I try adding it to my script, it says it doesn't exist. Was that added in a later version? I'm on 1.74.2.

    I tried using the OnEndActionList event just like you wrote, but it's not working (it works sometimes, I don't know why). I'm adding the ActionLists to my script as ActionListAssets. I don't if that changes anything.

    private void OnEnable() { EventManager.OnEndActionList += OnEndActionList; }
    private void OnDisable() { EventManager.OnEndActionList -= OnEndActionList; }
    
    void Update()
    {
            if (agent.reachedDestination && !reachedWaypoint)
            {
                reachedWaypoint = true;
                if (targets[index].GetComponent<AstarWaypoint>().actionList != null)
                {
                    currentActionList = currentWaypointDest.actionList;
                    currentActionList.Interact();
                    if (currentWaypointDest.waitDuringAction)
                    {
                       isWaiting = true;
                    }
                }
    
            }
    }
    
    private void OnEndActionList(ActionList actionList, ActionListAsset actionListAsset, bool isSkipping)
    {
        Debug.Log("ActionList " + actionList.name + " , " + actionListAsset.name);
        if (actionListAsset == currentActionList)
        {
            Debug.Log("ActionList done");
            if (isWaiting)
            {
                isWaiting = false;
            }
        }
    }
    

    I added the Debug.Log outside of the if statement to check if the event was called regardless of that. But it's not. Do I need to add anything somewhere else?

  • The code does seem to be working, but only sometimes. Other times it just straight up does not work.

  • AreActionsRunning is part of ActionList, i.e. the scene instance.

    If you're dealing with an ActionList asset, you can instead read:

    AC.KickStarter.actionListAssetManager.IsListRunning (myActionList);
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.