Version: Unity 6.6 Alpha (6000.6)
LanguageEnglish
  • C#

NoAutoStaticsCleanupAttribute

class in Unity.Scripting.LifecycleManagement

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

Prevents static variables from being automatically reset 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 not 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
{
    [NoAutoStaticsCleanup]
    public static int counter = 0;

void Start() { Debug.Log(counter); // Counter value is never reset counter++; } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961