Last active
May 27, 2020 15:31
-
-
Save nothke/30bfe14c55ba314ad714f80bb4e1bd6a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public static void SafeDestroy<T>(T obj) where T : Object | |
| { | |
| if (Application.isPlaying) | |
| Object.Destroy(obj); | |
| else | |
| Object.DestroyImmediate(obj); | |
| } | |
| // Call in OnValidate, OnTriggerEnter, etc, with StartCoroutine() out of play mode | |
| public static IEnumerator Catch22Destroy<T>(T obj) where T : Object | |
| { | |
| yield return null; | |
| SafeDestroy(obj); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment