Table of Contents

Nullable support for UnityEngine.Object

Runtime/UnityObject/NullableUnityObject.cs   HeaderDoc

(c) 2024 Sator Imaging, Licensed under the MIT License https://github.com/sator-imaging/Unity-Fundamentals

How to Use

Use .Nullable() extension method when using null-coalescing operator with UnityEngine.Object which may be null.

var rb = go.GetComponent<Rigidbody>().Nullable() ?? go.AddComponent<Rigidbody>();
var rb = go.GetComponent<Rigidbody>().Nullable() ?? throw new Exception();