Forum rules - please read before posting.

Follow NPC From Room to Room

edited August 21 in Technical Q&A

Hi everyone! It's been a while since I last posted in this group. I have a question about the best way to implement NPC following from room to room. Specifically, I need the NPC to follow the player when rooms switch (I use variables to control where everyone spawns), and the NPC needs to remember its position (I use Remember NPC).

I have some rudimentary logic set up, but things get complicated fast when the player re-enters a previously exited room, and the NPC needs to follow. I'm looking for advice on how to approximate somewhat realistic behavior. Any tips would be greatly appreciated! Thank you!

Comments

  • The best way to tackle this is to take advantage of the fact that AC records the scene and position of any Player listed in the Settings Manager - even if they are never actually directly controlled by the user.

    Conver the NPC to a Player (automated via the Inspector's cog menu), enable Player-switching, and assign this Player as an additional character there. You can then set their starting scene data, and reference them in Actions by checking Is Player?, and then selecting them from the drop-down.

    A guide to AC's Player-switching system can be found here.

  • edited August 22

    Please disregard this - I can't delete this, but I've found the answer in the link you sent and character switching. thank you.

    Hi Chris! Thanks for replying so quickly. If I convert NPCs to Players will I still be able to use "NPC Follows?". I did that to one of the enemies and now the trigger doesn't seem to work anymore. I still need them to be triggered to follow in that scene.

    Essentially this is the flow I need: Trigger NPC Follow in one scene, and when the character/player switches scenes I need a reliable way for the NPC/Enemy to follow the player and remember the last position without having to manually add all sorts of checks for spawn in the "On_Start" action lists, for each individual scene.

  • edited August 22

    Please disregard this - I can't delete this, but I've found the answer in the link you sent and character switching. thank you.

    https://drive.google.com/file/d/1-2XVi8NyPwisAnZpEL9L_uHnjH5XFnhD/view?usp=sharing <- here's a video of a test. I've added and NPC Follow and assigned the prefab. Still unsure on how to carry the follow action from scene to scene. I'll watch the video for Player Switching, but I already know how to do that.

  • When the Character: NPC follow Action affects a Player, you can check Follow across scenes? option to automate this behaviour.

  • edited August 24

    Hi again! I've set-up everything as specified in the tutorial, but I'm noticing an issue that's causing this not to work. I'm getting "Coroutine couldn't be started because the the game object 'Trigger2D:EnterScene' is inactive!". https://drive.google.com/file/d/1Hh944qfT5QEvCC4a7_mebS7YVdOSG-Lq/view?usp=sharing <- here's a screenshot of my setup. I have a feeling I'm doing something stupid, something obvious that I'm missing.

    here's a video of the issue: https://drive.google.com/file/d/1wK0ke-cq7zOheAJ05NBHAeloCVjMSMlw/view?usp=sharing

  • I'm not clear on the context - is this Trigger supposed to run whenever the scene begins?

    What's the error message in full - stacktrace included? I'm not sure if this is a separate issue. When an inactive Player follows the Player across a scene, they should transfer automatically - no need for a separate Player: Teleport inactive Action to bring them there.

    Does the switch occur naturally without the Trigger?

  • The Trigger is set to run just like the one in the Video you referenced. It's set it to On Exit and it just has the normal logic. I placed the Player/NPC in Room2 and I have a trigger on exit in Room 1. At first I figured maybe the NPC to Player script conversion broke, so I did a fresh Player, tried others, but it's still not working. Going to try to use this logic in a HotSpot Action list to see if this helps and I'll update in here. Thank you!

    When I exit the Trigger this is what I get:

    Coroutine couldn't be started because the the game object 'Trigger2D:EnterScene' is inactive!
    UnityEngine.MonoBehaviour:StartCoroutine (System.Collections.IEnumerator)
    AC.ActionList:ProcessAction (int) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:412)
    AC.ActionList:BeginActionList (int,bool) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:382)
    AC.ActionList:Interact (int,bool) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:283)
    AC.ActionList:Interact () (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:246)
    AC.AC_Trigger:Interact (UnityEngine.GameObject) (at Assets/AdventureCreator/Scripts/Logic/AC_Trigger.cs:331)
    AC.AC_Trigger:OnTriggerExit2D (UnityEngine.Collider2D) (at Assets/AdventureCreator/Scripts/Logic/AC_Trigger.cs:151)

  • https://drive.google.com/file/d/1CzQEMkNlHdMctrtU6ZmP0DjoI80BFBe5/view?usp=sharing <- Here's a test I made.

    https://drive.google.com/file/d/19OeH4djrRrwwI7ipyi-4aLAb3Oyy2-Jv/view?usp=sharing <- video.

    I Added this action list to a hotspot in the scene. And I Set Current Player to Sarah (I've tried active player too, same result), then I made a check if the Active player is in Room#1, then if the Inactive Player (SarahShotgun) is in Room#2, and if all these conditions are met to just prompt "Test" in dialogue, and nothing happens.

    There's also no error in the console, nothing.

  • The Trigger is set to run just like the one in the Video you referenced. It's set it to On Exit and it just has the normal logic.

    What I'm getting at is the placement - is it placed over the PlayerStart such that it runs immediately when the scene begins?

    The link is private.

    I Added this action list to a hotspot in the scene. And I Set Current Player to Sarah (I've tried active player too, same result), then I made a check if the Active player is in Room#1, then if the Inactive Player (SarahShotgun) is in Room#2, and if all these conditions are met to just prompt "Test" in dialogue, and nothing happens.

    And switching to Room#2 reveals SarahShotgun as being present there?

    Is this test being run from having previously visited Room#2, or are you starting the test from Room#1?

    I would suggest doing away with these Triggers for the moment - and create a pair of separate test scenes to test out the follow mechanics in. Have both Players start in the first scene, and have the inactive Player follow the active. Run a Cutscene that causes the active Player to switch scene, and see if the inactive (following) Player switches scene too.

  • edited August 26

    What I'm getting at is the placement - is it placed over the PlayerStart such that it runs immediately when the scene begins? - The Trigger is placed over the Custom 2d Markers I made. Based on what Room you're in and what Variable you enable, the character gets teleported onto a specific 2d Marker - in a specific position.

    And switching to Room#2 reveals SarahShotgun as being present there?
    Is this test being run from having previously visited Room#2, or are you starting the test from Room#1?
    - Yes, I visit Room#2 then go into Room#1 and then interact with the hotspot/Trigger. - You can see this in this video - https://drive.google.com/file/d/19OeH4djrRrwwI7ipyi-4aLAb3Oyy2-Jv/view?usp=sharing

    I will try your suggested method today. thank you

  • https://drive.google.com/file/d/1Fe40LWg9uU-KNx_iYBv9_MrzD0XwmBIq/view?usp=sharing <- Video

    I've done what you recommended, and it doesn't seem to work.

    What I've noticed is that I can't get an inactive player to follow me if I check the 'Move Inactive Player?' in NPC follow. I can only get them to follow if I physically place the inactive player in the scene and drag and drop it into NPC Follow.

    This is the setup from the video:

    1. I have two rooms, Boy-TestLights2 and Boy-TestLights. Both the player and the inactive player start in Boy-TestLights2. I have a hotspot that I click, which has an NPC follow (with the aforementioned issue about not being able to get an inactive player to follow), a wait of 3 seconds, and a Scene Switch to Boy-TestLights.

    2. In Scene Boy-TestLights, I have a cutscene action list assigned to the 'Scene cutscenes' On Start. I added some text at the beginning to make sure it actually triggers.

    You can see the setup here: https://drive.google.com/file/d/1GL_nwdxZ9-rva_hwYJLlTfLCy0fthZ41/view?usp=sharing

    My theory is that there's an issue with 'Inactive player' - I should be able to get an inactive player to follow without having to drag and drop them from the scene and by simply selecting them from the dropdown, correct?

  • Your Character: NPC follow Action doesn't reference an inactive Player - but an NPC within the room.

    Remove the NPC from the scene, and have SarahShotgun appear in the scene by default (e.g. by updating their "start data" in the Settings Manager).

    Have the Action reference this Player, and then check Follow across scenes?.

    You shouldn't then need to rely on any Player: Teleport inactive in the following scene - SarahShotgun should move to the new scene automatically.

  • edited August 28

    Ah, that was the problem. I was suppose to Spawn that NPC via On_Start and not drag it in the starting scene. It works now. I knew it had to be something dumb on my part. Question. I was looking in the manual and eveywhere else, but I can't seem to be able to find Follow across scenes?.. Where is this option? Also, thank you for the help.

  • It will appear in the Character: NPC follow Action, once Move inactive Player? is checked.

  • ah, duh, found it! thank you. thank you for the 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.