Documentation

Unity Engine

Unity Engine

NoAutoStaticsCleanupAttribute

Prevents static variables from being automatically reset on entering or exiting Play mode with code reload disabled.
Read time 3 minutesLast updated 4 days ago

Definition

[AttributeUsage(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Event, AllowMultiple = false)]public sealed class NoAutoStaticsCleanupAttribute : Attribute

Remarks

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 not reset. For more information, refer to Enter Play mode with code reload disabled in the manual.

Examples

using Unity.Scripting.LifecycleManagement;using UnityEngine;[AutoStaticsCleanup]public partial class MyCounterClass : MonoBehaviour{ [NoAutoStaticsCleanup] public static int counter = 0; void Start() { Debug.Log(counter); // Counter value is never reset counter++; }}

Constructors

Constructor

Description

NoAutoStaticsCleanupAttribute()Marks the decorated type or member so Unity doesn't reset its static state automatically.

Inheritance

Inherited Members