Last active
July 30, 2019 15:35
-
-
Save michaelbartnett/0afeb027a535e3e9f24a983b2f23d44f to your computer and use it in GitHub Desktop.
unity null fun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
interface ISomeInterface | |
{ | |
} | |
public class TestScript : MonoBehaviour, ISomeInterface | |
{ | |
} | |
public class NullTest : MonoBehaviour | |
{ | |
void OnEnable() | |
{ | |
var go = new GameObject("destroyme"); | |
TestScript nullButNotReally = go.AddComponent<TestScript>(); | |
DestroyImmediate(go, true); | |
Debug.Log($"nullButNotReally == null :: {nullButNotReally == null}"); | |
ISomeInterface asInterface = (ISomeInterface)nullButNotReally; | |
Debug.Log($"asInterface == null :: {asInterface == null}"); | |
Debug.Log($"{(nullButNotReally?.ToString() ?? ("elvis operator operator object returned null"))}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment