Skip to content

Latest commit

 

History

History
39 lines (31 loc) · 796 Bytes

File metadata and controls

39 lines (31 loc) · 796 Bytes

UNT0040 GameObject.isStatic is editor-only

GameObject.isStatic is only usable in the Editor. In builds, it always returns false. Use editor-only code or editor callbacks like OnValidate/Reset when accessing isStatic.

Examples of patterns that are flagged by this analyzer

using UnityEngine;

class Camera : MonoBehaviour
{
    void Start()
    {
        if (gameObject.isStatic)
        {
            // This will never execute in builds
        }
    }
}

Solution

Use it within editor-only Unity messages like OnValidate or Reset:

using UnityEngine;

class Camera : MonoBehaviour
{
    void OnValidate()
    {
        if (gameObject.isStatic)
        {
            // This is acceptable because OnValidate is editor-only
        }
    }
}