Forum rules - please read before posting.

How to keep variable values between scene changes

In my game, I have a door that requires a key to unlock it. There is a bool (isLocked) that changes from true to false once the key is used, allowing the player to leave and switch to a new scene (outside). However, if I choose to reenter the room, the door is locked and the key is back where it originally spawned, causing the player to unlock the door every single time they want to leave the room again.
How can I make it so the door stays unlocked and the key does not spawn after being picked up and added to the inventory?

Comments

  • It's a case of attaching the correct "Remember" component to your objects, in order to flag their data for saving.

    What is your bool variable's type? If it's a Global or Local variable, its value will be saved automatically. If it's a Component variable, you'll need to attach the Remember Variables component to have its value saved.

    For the key: it depends on how you're removing it from view once the player takes it. If you teleport it away, attach the Remember Transform to record its change in position. If you make it invisible and disable its Hotspot, use the Remember Visibility and Remember Hotspot components.

    The process of adding Remember components can be automated via the Settings Manager's "Auto-add save components to GameObjects" button inside the "Save game settings" panel.

    For more on this topic, see the Manual's "Saving scene objects" chapter.

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.