MyClass go = new MyClass();
go = null;
Debug.log($"A = {go == null}");
Debug.log($"B = {ReferenceEquals(go, null)}");
GameObject go = new GameObject();
Destory(go);
Debug.log($"A = {go == null}");
Debug.log($"B = {ReferenceEquals(go, null)}");
yield return null;
Debug.log($"C = {go == null}");
Debug.log($"D = {ReferenceEquals(go, null)}");
C++ Native 객체는 삭제되었지만, C# Wrapper 객체는 아직 남아 있는 상태이다. Unity는 UnityEngine.Object의 == 연산자를 오버로딩하여 이를 null로 취급한다.
null 은 어떤 객체도 참조하지 않는 실제 C# null"null" 로 보이도록 fake null 처리== 연산자 오버로딩== 연산자는 일반 C# 참조 비교보다 조금 더 비싸다?? 이나 ?. 연산을 사용할 때 주의가 필요하다GameObject go = new GameObject();
Destroy(go);
yield return null;
if (go != null)
{
go.transform.position = Vector3.zero;
}
if ((object)go == null) 로 == 연산자 오버로딩 우회 가능