class in Unity.Scripting.LifecycleManagement
Resets static variables automatically on entering or exiting Play mode with domain reload disabled.
This attribute can be applied to classes, structs, fields, properties, and events. Applying it to a class or struct ensures all static members of the class or struct are automatically reset. For more information, refer to Enter Play mode with domain reload disabled in the manual.
using Unity.Scripting.LifecycleManagement; using UnityEditor.Scripting.LifecycleManagement; using UnityEngine; public partial class MyCounterClass : MonoBehaviour { [AutoStaticsCleanup] public static int cleanedUpCounter = 0;
void Start() { Debug.Log(cleanedUpCounter); // Counter value is reset each time entering Play Mode cleanedUpCounter++; } }