Skip to content

Instantly share code, notes, and snippets.

@michaelbartnett
Last active July 30, 2019 15:35
Show Gist options
  • Save michaelbartnett/0afeb027a535e3e9f24a983b2f23d44f to your computer and use it in GitHub Desktop.
Save michaelbartnett/0afeb027a535e3e9f24a983b2f23d44f to your computer and use it in GitHub Desktop.
unity null fun
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