Forum rules - please read before posting.

Cutscene.Kill doesn't stop ongoing action move to point

Hello,

I have an NPC moving in background using cutscene from one point to another. (Action in scene with Run in Background).

I want that when another cutscene that pauses gameplay (has set "when running" to "pause gameplay") and involves that NPC to make him stop moving from point to point and run a talk animation.

The Kill() method doesn't stop MoveToPoint for some reason. The character just moves to the point and gets stuck like below.


Each Walks and Runs are a List with a MoveToPoint Action.

 IEnumerator GoToTarget() {
        yield return new WaitForSeconds(1);
        while (true) {
            if(alm == null) {
                yield return new WaitForEndOfFrame();
            }
            if (alm.IsGameplayBlocked()) {
                for (int j = 0; j < Spots.Count; j++) {
                    if (Walks[j].AreActionsRunning()) {
                        Walks[j].Kill();
                    }
                    if (Runs[j].AreActionsRunning()) {
                        Runs[j].Kill();
                    }
                }
                yield return new WaitForSeconds(0.5f);
                continue;
            }
            int i = 0;
            float dist = Mathf.Infinity;

            //find the closetest point
            for (i = 0; i < Spots.Count; i++) {
                if (dist > (Spots[i].transform.position - Kitteh.position).magnitude && IsOk(Spots[i])) {
                    dist = (Spots[i].transform.position - Kitteh.position).magnitude;
                    close = i;
                }
            }
            
            //check if an action is running
            bool walkOrRunIsRunning = false;
            for (i = 0; i < Spots.Count; i++) {
                if (Walks[i].AreActionsRunning()) {
                    walkOrRunIsRunning = true;
                }
                if (Runs[i].AreActionsRunning()) {
                    walkOrRunIsRunning = true;
                }
            }
            //run if far away
            if ((Kitteh.position - Buzz.position).magnitude > 6f) {
                if (!walkOrRunIsRunning) {
                    Runs[close].Interact();
                }
            }//walk to point
            else if ((Kitteh.position - Buzz.position).magnitude > 2.5f) {
                if (!walkOrRunIsRunning) {
                    Walks[close].Interact();
                }
            }//run to point
            else if ((Kitteh.position - Buzz.position).magnitude < 1f) {
                if (!walkOrRunIsRunning) {
                    Runs[close].Interact();
                }
            }
            yield return new WaitForSeconds(0.5f);
        }
    }

Comments

  • I found out if I use  Kitteh.GetComponent<AC.NPC>().Halt(); the character stops in place, and plays part of the animation.

    I am looking into a solution, ideally either to stop the NPC and her talk then continue moving, OR at least add the new talk cutscene to a list to do that one after it has finished the current movement.
  • I got everything to work with something like this, I halt the player and not only kill the action list and then I pause all active lists, then I do the inbetween animations, then I resume all the active lists. 

    if (Walks[j].AreActionsRunning()) {
                            Walks[j].Kill();
                            Kitteh.GetComponent<AC.NPC>().Halt();

                            PauseAllActiveLists();
                            
                            //Do the StopSit animation
                            Walks[j].Interact(3, false);

                            //Continue with the action list that wanted to run before this
                            ResumeAllActiveLists();
                        }

    /*
         * <summary>Pauses active lists that are of type PauseGameplay</summary>
         */
        void PauseAllActiveLists() {
            activeListsWerePaused = true;
            for (int jj = 0; jj < alm.GetActiveList().Count; jj++) {
                if (alm.GetActiveList()[jj].actionList.actionListType == AC.ActionListType.PauseGameplay) {
                    alm.GetActiveList()[jj].actionList.Pause();
                }
            }
        }

        /*
         * <summary>Resumes active lists that are of type PauseGameplay</summary>
         */
        void ResumeAllActiveLists() {
            if(!activeListsWerePaused) {
                return;
            }
            activeListsWerePaused = false;
            for (int jj = 0; jj < alm.GetActiveList().Count; jj++) {
                int[] _res = new int[1];
                _res[0] = 0;
                if (alm.GetActiveList()[jj].actionList.actionListType == AC.ActionListType.PauseGameplay) {
                    alm.GetActiveList()[jj].actionList.Resume(0, _res, "");
                }
            }
        }
  • The ActionList.Kill() command, by design, won't affect anything the Actions themselves are handling - it will merely prevent those Actions from doing anything further.

    Halting the character manually is indeed the method required, and pausing/resuming the ActionList should also allow you to return afterwards.  You can do these via the Character: Move along path and ActionList: Pause or resume Actions respectively - which may be easier than coding it.
  • I have inbetween animations for my NPC and that's why I have to go through all this struggle. I don't want the NPC to jump from walking to a talk animation, but first wait for an inbetween animation to sit. The thing is that I managed to stop and resume the action list, the only problem I am having now is with the Action->MoveToPoint.

    So if I start an interaction with an Action->MoveToPoint, I stop that action list, I use on player either the Halt() or EndPath() method, wait for the inbetween animation, and then I resume the ActionList. And here comes the problem. The first action in the action list is Action->MoveToPoint. And has a "wait until finished" as marked. But for some reason when I resume the action list, it just jumps over that Action->MoveToPoint.

    And I don't know why it doesn't properly do Action->MoveToPoint anymore, until I just click an empty space somewhere and my Player just moves there.

    Even is I use .actionList.ResetList(); actionList.Interact();, OR if I use actionList.Resume(0, _res, ""); it's the same. The first node with MoveToPoint gets ignored, as in not waiting for it to complete.

    I also noticed inside the Editor that sometimes for the Player I see the blue trajectory to move when the action list starts, but it doesn't move at all.
  • So what I do is this:
    1. Pause the current actionList
    2. Halt or EndPath of the Player
    3. Wait for a fixed amount of time
    4. Resume the actionList either by Reset and Interact of simply Resume, I make sure its from the very first node or action
    5. If there is a MoveToPoint in the actionList, it wont wait for it to complete and just jump over it, as in, ignore wait until finished.
    Any help is greatly appreciated and I thank you very much for the great support.
  • edited March 2017
    As pausing the ActionList does not cease the currently-running Action (you're doing that manually afterwards), resuming it should indeed cause that Character: Move to point Action to be bypasses, since so far as AC is concerned that Action was already run.

    However, restarting the ActionList should cause the Action to re-run, and if the blue line is showing it sounds like it is - but not having an effect.

    You can confirm that the Action is running by toggling on a comment (top-right corner icon of the Action), and outputting it to the Console from the bottom of the Settings Manager.  Incidentally, do any other messages appear in the Console?

    This actually sounds like an issue with your character rather than the ActionList system.  Can you try placing in Brain2D, from the 2D Demo, and trying him out?  I can't recreate this problem by following your steps with him.
  • Hello,

    Thanks for the fast replay. With your help I found the right order to do things. Indeed the Action was being called but even if I resume the ActiveList from position 0, has no effect as you said. So it needed a reset and interact, but that was not enough, I had to stop both player and NPC with EndPath. So it was more of a situation to understand what goes on under the hood. The correct order is this:

    1. Kill my NPC's walk interaction and EndPath()
    2. Player.EndPath()
    3. Pause all active lists which have set the param: gameplay pause
    4. Do the inbetween animation
    5. Wait for the animation to finish
    6. Then Reset and call Interact on the active List.
    7. Run this Routine as yield new WaitForEndOfFrame
    Now it works how I wanted it to work. Yay!
    It's so good to have someone to bounce ideas of, being the only developer on the project. And I really like the way you wrote AdventureCreator. The more I understand it, the more I appreciate it.
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.