Adventure Creator Wikia

When a GameObject is disabled and later re-enabled, its Animator component resets its parameter values back to their default states. This component backs up these values when disabled, and restores them when re-enabled.

This is useful when using an Animator inside a Unity UI-based Menu, since UI menus are disabled when not in use.

To use it:

  1. Copy the script below into a new C# file named SaveRememberOnDisable.cs
  2. Attach the new Save Remember On Disable component to the Animator
  3. Attach a Remember Animator component to the Animator if it doesn't yet have one

NOTE: Make sure the Remember Animator component to below the Save Remember On Disable component in the Inspector

SaveRememberOnDisable.cs:

using UnityEngine;

namespace AC
{

public class SaveRememberOnDisable : MonoBehaviour
{

private Remember remember;
private string disabledData;

private void Awake ()
{
remember = GetComponent<Remember> ();
}

private void OnEnable ()
{
if (!string.IsNullOrEmpty (disabledData))
{
remember.LoadData (disabledData);
disabledData = string.Empty;
}
}


private void OnDisable ()
{
disabledData = remember.SaveData ();
}

}

}