Adventure Creator Wikia
Advertisement

Remember components are used to save data about objects in the scene, and are saved automatically when the game is saved or the scene is closed.

But if you have an object that's only in the scene for some of the time (i.e. spawned in temporarily and then removed), its Remember data will not be part of the save file. This script allows you to store such data in a Global variable when the object is disabled, and loaded in again when enabled.

To use it:

  1. Create a new C# script named RememberToVariable.cs, and paste in the code below
  2. Create a new Global Variable and set its Type to String
  3. Attach the new Remember To Variable component to a prefab that gets spawned in and removed at runtime
  4. In its Inspector, assign the Remember component you wish to save, as well as the ID of the variable to store its data in.

RememberToVariable.cs:

using UnityEngine;

namespace AC
{

public class RememberToVariable : MonoBehaviour
{

[SerializeField] private int linkedVariableID = 0;
[SerializeField] private Remember remember = null;


private void OnEnable ()
{
GVar linkedVariable = GlobalVariables.GetVariable (linkedVariableID);
if (linkedVariable != null && !string.IsNullOrEmpty (linkedVariable.TextValue) && remember)
{
remember.LoadData (linkedVariable.TextValue);
}
}


private void OnDisable ()
{
GVar linkedVariable = GlobalVariables.GetVariable (linkedVariableID);
if (linkedVariable != null && remember)
{
linkedVariable.TextValue = remember.SaveData ();
}
}

}

}
Advertisement