Skip to content

Remember

The Remember component allows to cherry-pick the data that is stored when saving the game. By default, it stores the position, rotation and scale.

Remember

To add a new element to be saved, click on the Add Memory button and select the type of data to save.

Creating a Memory

Game Creator comes with a set of default memories, but you can create custom ones that extend the data stored. To create a new Memory create a new class that inherits from the Memory class. For this example, we'll create a memory that saves name of the game object attached to this memory.

[Serializable]
public class MemoryName : Memory
{
    public override string Title => "Name of Game Object";

    public override Token GetToken(GameObject target)
    {
        return new TokenName(target);
    }

    public override void OnRemember(GameObject target, Token token)
    {
        if (token is TokenName tokenName)
        {
            target.name = tokenName.text;
        }
    }
}

The Title property determines the name of this memory. This has no effect on the data stored but it displays this value on the Inspector.

The GetToken(...) method returns the Token instance of this memory and is called when the game data is scheduled to be saved. A Token is a data container that contains the data to be stored. In this case, we'll need to create a new class called TokenName that inherits from Token and has a serializable field to save the name of the object.

[Serializable]
public class TokenName : Token
{
    public string text;

    public TokenName(GameObject target) : base()
    {
        this.text = target.name;
    }
}

The OnRemember(...) method is called when loading a previously saved game and is used to restore its state. In this case, it changes the name of the game object to the one it tries to remember.

Decorations

The custom Memory class instance can be decorated using any of the attributes found in the Instruction, Condition and Event classes.