Skip to content

Codeavr/UnityObjectExtensions

Repository files navigation

UnityEngine.Object Extensions

Why

  1. Enable null-propagation

    var rb = GetComponent<Rigidbody>();
    rb.Nullable()?.AddForce(Vector3.forward);
  2. Safe get component

    var rb = GetOrAddComponent<Rigidbody>();
    rb.AddForce(Vector3.forward);
  3. Unity unmanaged safe-check

    Destroy(someUnityObject);
    
    print(someUnityObject == null);         // true
    
    object regularObject = someUnityObject;
    
    print(regularObject == null);           // false
    print(regularObject.IsUnityNull());     // true

Install

Find Packages/manifest.json in your project and edit it to look like this:

{
  "dependencies": {
    "com.codeavr.unity-object-extensions": "https://github.com/Codeavr/UnityObjectExtensions.git"
  }
}

Requirements

  • Unity any version
  • Git

License

  • MIT

About

Useful UnityEngine.Object extensions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages