Null Utilities - BluePixelDev/utilkit GitHub Wiki
The NullFunc
class provides a set of extension methods for simplifying null and Unity destroyed object checks. These utilities help you write cleaner, more concise conditional logic by encapsulating common null
or destroyed
object patterns.
WithNotNull
Invokes an action only if the object is not null or destroyed.
myObject.WithNotNull(obj => obj.DoSomething()); // Pass the object into the action
myObject.WithNotNull(() => Debug.Log("Safe to proceed.")); // No object required in action
WithNull
Invokes an action only if the object is null or destroyed.
myObject.WithNull(obj => Debug.Log("Object is null")); // Access object if needed
myObject.WithNull(() => Debug.Log("Object is null")); // No object required in action
IsNull
Checks whether the object is null
or a Unity object that has been destroyed.
Using simple == null
doesn't work for destroyed objects.
if (myObject.IsNull()) {
Debug.Log("This object is null or has been destroyed");
}