class in Unity.Scripting.LifecycleManagement
/
Inherits from:Unity.Scripting.LifecycleManagement.LifecycleAttributeBase
Marks a static method as a callback to be invoked after managed objects have been restored following a code reload.
Methods marked with this attribute are called after Unity has restored (deserialized) managed objects following a code reload. At this point:
Awake/OnEnable calls.Use this callback to:
This is a method attribute that can only be applied to static methods with no parameters and return type void.
Additional resources: OnCodeDeinitializingAttribute, OnCodeLoadedAttribute
using Unity.Scripting.LifecycleManagement; using UnityEngine;
public static partial class GameManagerRegistry { [OnCodeInitializing] static void RebuildRegistry() { var managers = Object.FindObjectsByType<GameManager>(FindObjectsSortMode.None); Debug.Log($"Found {managers.Length} GameManager instances after restore");
foreach (var manager in managers) { Debug.Log($"Manager '{manager.name}' state: {manager.savedState}"); } } }
public class GameManager : MonoBehaviour { public string savedState = "Initial"; }