Forum rules - please read before posting.

Moving NPC through multiple rooms in 1 scene when variable changes

edited June 2019 in Technical Q&A

Hi, I am using the latest AC on Unity 2018.1.0f2.

I have a scene set up with about 10 different nav meshes and sorting maps to enable the player and NPCs to move through different rooms.

I want one of my NPC's to move from its position in room 1 to the 'door',
then teleport and move from that door to the next in room 2, then object teleport
and come to a stop in room 3, all within the same scene.

When the player interacts with a hotspot this changes the boolean variable moveNPC to true.
I have a cutscene set to 'run in background' checking for this variable and when it changes,
this triggers the cutscene ActionList to move the player through the rooms.
I was getting strange results using 'character': 'move to point', I presume because the NPC was not moving on the active navmesh, so I set up 3 paths to move the NPC along, one for each room to be navigated.

Either way, both methods only work with 'wait until finished' checked, which means that my player freezes until the NPC arrives in the room. This is not the result I am looking for. I want the player to be able to move freely whilst the NPC is moving alongs its route. How do I do this?

If I uncheck 'wait until finished' then the NPC just immediately teleports to the final marker...

Comments

  • An ActionList can still wait while an Action completes, but not interrupt gameplay - just set its When running field to Run In Background at the top of it's Inspector.

    Seems strange to continually check for "moveNPC", however. You'd have to be careful to make sure this doesn't cause the ActionList that actually moves the NPC to be triggered on a loop. Best to just run it as part of the Hotspot interaction if you can.

    If the NPC is outside of the active NavMesh, then yes - you'll need to define Paths for the NPC to be able to walk without the aid of dynamic pathfinding. However, if each NavMesh is isolated (i.e. they don't overlap), you can add them all to the same NavMesh gameobject and they should all work at the same time - see the "Polygon Collider pathinding" chapter in the Manual for more.

  • 'Great, thanks. Then perhaps my question is more simple: How do you set an action to run in the backgroun when it is based on a hotspot? I can't find this option in the inspector... only on cutscene-actionlists and asset-actionlists...'

    Would have been my response, BUT I FOUND IT! yay!

    I will leave this here for others and for my future self: The toggle for a hotspot actionlist to 'run in background' is inside the Actionlist Editor under the 'show properties' tag in the bottom left corner

  • Hello. I've come back around to a similar problem to the one above. I'm looking for a bit more clarity as to why it doesn't work the way I want it to so I can understand things better.

    I made a pretty picture to help: https://imgur.com/MRj0JhZ

    I have a bunch of hotpots in a room. Each time my player looks at a new hotspot, the Action Script attached to the 'look at' Interaction for the hotspot causes a local integer variable (CountHotspot) to increase its value by 1. i.e. the order in which the player looks at the various hotspots is irrelevant.

    When the CountHotspot value reaches 2, 4 and 6, I want various events to be triggered.

    I tried doing this by creating an empty game object Interaction called TriggerAction that floats unseen in the room. The action script of TriggerAction contains a Variable: Check action that is set to produce various events at values 2, 4 and 6 of CountHotspot. It is set to Run in Background.

    It is not working. The CountHotspot is counting properly, but when it reaches the relevant number, nothing is triggered. Why is this not working?

    I can of course set the events to be triggered from inside each of the 'look at' Interactions, but I don't understand why my approach wouldn't work and be a more efficient method to trigger the results I want. For example, imagine if I want events to be triggered at 2, 4, 6, 8, 10, ... n etc. I would have to fill each of the hotspots to be looked at with additional action lists for each of the events.

    Any advice or thoughts welcome. Thanks.

  • How or when is "TriggerAction" being told to run?

    If you moved those Actions to a Cutscene instead, you could then rely on a custom script to run it automatically whenever a Hotspot interaction has completed, i.e.:

    using UnityEngine;
    using AC;
    
    public class RunCutsceneAfterInteraction : MonoBehaviour
    {
    
        public Cutscene cutsceneAfterInteraction;
    
        private void OnEnable () { EventManager.OnEndActionList += OnEndActionList; }
        private void OnDisable () { EventManager.OnEndActionList -= OnEndActionList; }
    
        private void OnEndActionList (ActionList actionList, ActionListAsset actionListAsset, bool isSkipping)
        {
            if (actionList is Interaction) cutsceneAfterInteraction.Interact ();
        }
    
    }
    
  • Ah! I have the feeling I am always asking questions on an incredibly simple level.
    In this case your initial question, > How or when is "TriggerAction" being told to run?
    is enough to move me forwards. Thanks.

    I was assuming that Interactions placed in the scene would simply run on their own. That is a great help.

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.