Forum rules - please read before posting.

Component variables on NPCs resets during scene switch.

edited June 2023 in Technical Q&A

Hello, currently, I'm utilizing component variables on NPCs to keep track of whether the player has interacted with them for the first time. To achieve this, I have attached the "Remember Variables" component and ensured that the "Retain in Prefab" option is checked. However, when I switch scenes and then return, the variables reset to their default values. I'm not attempting to save the game, but rather aiming to maintain the values of the component variables even when scenes are switched. I'm also using the "remember NPC" component. Is there something I might be overlooking in this process? Just to clarify, I'm dynamically adding the NPC from prefab to the scene depending on the value of a global variable, which serves as an objective.

Comments

  • edited June 2023

    Great! It seems like I've resolved my issue by including an NPC instance within the scene. Right now the variables working in this scene is enough for me. I'll continue testing it and will reach out if I encounter any further complications with the setup. Thank you.

  • I had the understanding that the "retain in prefab" feature in the "Remember Variables" component would transfer the values to prefabs and, therefore, persist across different scenes. Is my understanding correct? Please correct me if I'm mistaken.

  • The "Retain in prefab?" option only refers to the ID number assigned to the component - it's not related to the data that the component saves.

    If you check this box, then each time you place the NPC in a scene, it'll always have the same ID. This means that asset-based Actions etc can always refer to it regardless of which scene is open.

    A pair of tutorials that cover this concept can be found here.

    If you are spawning an object in at runtime, you will need to make use of the Remember Transform component to save its presence.

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.