Skip to content

Latest commit

 

History

History
33 lines (24 loc) · 669 Bytes

File metadata and controls

33 lines (24 loc) · 669 Bytes

UNT0030 Calling Destroy or DestroyImmediate on a Transform

Calling Object.Destroy or Object.DestroyImmediate using a Transform argument is not allowed and will produce an error message at runtime.

Examples of patterns that are flagged by this analyzer

using UnityEngine;

class Camera : MonoBehaviour
{
    public void Update() {
        Destroy(transform);
    }
}

Solution

Destroy the related GameObject instead:

using UnityEngine;

class Camera : MonoBehaviour
{
    public void Update() {
        Destroy(transform.gameObject);
    }
}

A code fix is offered for this diagnostic to automatically apply this change.