Forum rules - please read before posting.

NPCs reset to original position on game load

edited August 2019 in Technical Q&A

Hello all again. Dave again with another newbie question.

So I have an NPC named Joe. At the start of the game, Joe is in an alleyway. At one point, you can go up to Joe, talk to him, and he starts following you around. If I save the game at this point, and then reload, Joe is back in the alleyway and isn't following me anymore.

I also set up some random NPCs walking around the street (following a path on a ping-pong loop). When I reload a game, these NPCs are standing stock-still in the positions that I originally placed them.

I have a constant ID component attached to all these NPCs, so I am confused.

Thanks in advance! :smiley:

-Dave

Comments

  • Aha. RTFM, Dave. I discovered the "Remember NPC" component.

    That said, I feel like this is something that should be automatically added when you press the "Auto-add save components to game objects" button. Or does it do that already and I did something wrong?

  • edited August 2019

    Aaand now I'm facing a similar issue in the same vein. Sorry for the triple posting. I will apologize again if I solve it myself again.

    When Joe is following me, I set him up so his head is always facing my player character. When I try saving now, I get an error saying that his neck was not saved because it does not have a Constant ID (proven when I reloaded and his head wasn't facing me anymore).

    I added a Constant ID to his neck an I still get the error.

    Here is a screenshot sort of showing the problem: https://imgur.com/a/TKbIHbr
    (apologies for the nudity! we haven't made clothing for all our models yet)

    Thanks again in advance!

    -Dave

  • I feel like this is something that should be automatically added when you press the "Auto-add save components to game objects" button.

    It should do. Is the Character: NPC follow Action in an asset file or a scene-based ActionList e.g. a Cutscene?

    When I try saving now, I get an error saying that his neck was not saved because it does not have a Constant ID

    Perhaps the log message could be rewritten to be more clear, but it's referring to the "Neck" GameObject of your Player character - not that of the NPC. The ConstantID component is used to create a reference for where the NPC is looking.

  • Thanks for the help, Chris!

    The follow action is in a scene-based action list, yes.

    The log message refers to "Joe", who is an NPC not the player character. When I reload, the player's head turning gets carried over just fine. So I'm a bit confused by that.

  • Oh you mean the player's neck needs to have a constant ID! OK I did that and that fixed it. Is this be something that should be added to the auto-add button as well? Or did I do something wrong again?

  • edited August 2019

    You did nothing wrong, but the auto-add feature isn't 100% reliable. I shall see about fixing this specific scenario, though.

  • Hi. I’ve since added new characters and the “Remember NPC” component still isn’t getting added when I press the auto-add button. I set the character walking in a path from within an action list. Is there something else I’m missing?
  • edited August 2019

    Some more info. The path that the character is following gets a constant ID attached to it just fine, but not the character.

    Here's a screenshot of the actionlist command if that helps. This was taken after I pressed the auto-add button: https://imgur.com/a/c0poU7B

  • edited August 2019

    All looks fine from the screenshot - it should be added. That the Path is getting a ConstantID component means that the function is being run, just that the RememberNPC is left out. I can't recreate the issue on my end.

    If you're interested in doing some debug logging, the function in question is the AssignConstantIDs method inside ActionCharMove.cs. "saveScriptsToo" is True when called, and the conditions for adding RememberNPC all look met to me (isPlayer being False, and charToMove being set to an NPC).

  • Pardon my duncey question, but I'm afraid I'm too new to Unity to quite understand what you're asking me to do. How can I check the variables when I press the "auto-add" button since I can't have two items on the inspector at the same time?

  • edited August 2019

    OK now I'm experiencing even more Save/Load weirdness.

    I was experimenting with another skybox, and then decided I did not like it. So I reverted it back.

    Now when I save my game and reload, it reloads WITH THE OTHER SKYBOX'S LIGHTING (although the correct skybox is in place). How is this even possible? Any idea what might be causing this?

  • You can monitor all variable changes live whilst playing in the Variables Tab of the AC Game Editor.

  • Pardon my duncey question, but I'm afraid I'm too new to Unity to quite understand what you're asking me to do. How can I check the variables when I press the "auto-add" button since I can't have two items on the inspector at the same time?

    This isn't anything to do with variables or Inspectors. I'm talking about editing the script so that a Console message can reveal more about what it's attempting to do.

    Open up ActionCharMove.cs, and find the AssignConstantIDs function - should be around line 365.

    Inside the "if (saveScriptsToo)" section, paste the following:

    Debug.Log ("Want to assign RememberNPC to " + charToMove + ", isPlayer: "+ isPlayer);
    if (charToMove) Debug.Log ("NPC component: " + charToMove.GetComponent <NPC>(), charToMove);
    if (charToMove) Debug.Log ("Remember NPC component: " + charToMove.GetComponent <NPC>(), charToMove);
    

    Re-run the auto-add operation. What appears on the console then?

    Now when I save my game and reload, it reloads WITH THE OTHER SKYBOX'S LIGHTING (although the correct skybox is in place). How is this even possible? Any idea what might be causing this?

    AC won't save any such data, so I suspect this is a Unity issue. Are you certain the old lighting is there, or is the lighting just different? If a scene is reloaded in Unity Play Mode, it can lose auto-baked lighting. Does this occur in an actual build?

  • Huh. I tried my game this morning and the lighting issue seems to have gone away. I guess the QA fairy visited me in the night.

    I'll try the debug thing when I've had some coffee. :D

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.