Forum rules - please read before posting.

Remember Variables on Menu Prefabs

edited July 2020 in Technical Q&A

Is it possible to put remember variables on a the prefab of an AC menu (ie the menu's source is a unity prefab and not in scene)? And if so, how do I make them save correctly? I've got remember variables working fine on scene objects but I can't make it work on the menu. When I inspect the save file (a json), I get two versions of it against its constant id. The first is saving the default values and the other is saving the correct values. But then when I start the game, the saved values don't come through. It's like they are being wiped by the default values.

I could save it elsewhere but it would be the neatest solution to have them on the prefab and because they are appearing in the save file, I feel like it should be possible.


  • edited August 2020

    With v1.71, AC will save Remember component data found on persistent objects (i.e. those in the DontDestroyOnLoad scene) as global data - not scene data. Just be sure to check Retain in prefab? on the prefab itself so that its Constant ID is always consistent.

    The issue with UI prefab menus is that they need to be disabled when not visible (to avoid some unwanted interaction issues with the Unity UI system), and so they won't be included in save-game data as AC can only save enabled object states.

    This is only an idea, but you could try putting the Variables / Remember Variables pair onto a separate child of the prefab, and then also attach a simple script to it that detaches it from the rest of the UI but still keeps it persistent. Unity should still retain references made to it, and it'll revert back when you exit Play mode.

    Something like this:

    using UnityEngine;
    public class DetachFromParent : MonoBehaviour
        void Awake ()
            transform.SetParent (null);
            DontDestroyOnLoad (gameObject);
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.