Created
January 13, 2019 13:28
-
-
Save SeppahBaws/bca394e159f71bdfd5335613f50b1bc4 to your computer and use it in GitHub Desktop.
This is a simple function that makes checking variables for null much easier. It can even log a simple message. (in this case to the Unity debug console)
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 class Utils | |
| { | |
| public static bool NullCheck(this object obj, string msg = "") | |
| { | |
| if (obj == null) | |
| { | |
| if (msg != "") | |
| Debug.LogError(msg); | |
| return true; | |
| } | |
| return false; | |
| } | |
| } | |
| // --- Usage: --- | |
| Transform someObj = transform.Find("SomeChild"); | |
| if (someObj.NullCheck("someObj not found!")) return; | |
| // do stuff with someObj | |
| // ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment