Smooth Operator

Use modern C# null syntax safely with Unity objects.

Smooth Operator is a Unity extension focused on one problem: Unity objects do not behave like normal CLR references around `?.` and `??`. This tool makes those operators usable without the missing-reference surprises that normally come with Unity’s custom null model.

The Problem

Unity null is not normal C# null.

Unity uses a custom equality implementation on `UnityEngine.Object` to detect destroyed native-side objects. The null conditional operator and null coalescing operator cannot use that custom behavior, because those operators are not overloadable in C#.

That means code that looks like ordinary C# can still behave incorrectly with Unity objects after the native object has been destroyed. Smooth Operator exists to close that gap.

Why `?.` and `??` are risky in Unity by default

Unity can make a destroyed object compare equal to null through its overloaded equality rules, but `?.` and `??` still use regular reference null checks. That mismatch is the core issue Smooth Operator addresses.

Before / After

Cleaner syntax, same intent.

The old version works, but it spreads the null handling across more branches and more visual noise. Smooth Operator compresses the same intent into code that is easier to read in motion.

BeforeAfterUnity null checks -> null operators
Typical defensive Unity codeVerbose, defensive flow
1if (rigidbody != null)
2{
3rigidbody.AddForce(force);
4}
5
6var targetName = target != null
7? target.name : "None";
Modern syntax with Smooth OperatorSame behavior, cleaner syntax
1rigidbody?.AddForce(force);
2
3var targetName = target?.name
4?? "None";
Fewer branches

The safety checks stay in the code path without forcing the surrounding method to sprawl.

Same intent

Nothing about the gameplay logic changes. The syntax just becomes easier to scan and maintain.

Unity-aware behavior

Smooth Operator keeps the result aligned with Unity object semantics instead of plain CLR null checks.

How It Works

Keep the syntax. Restore the expected behavior.

Smooth Operator transforms the relevant code paths so Unity’s overloaded null check is used instead of a plain reference null check. The result is that `?.` and `??` behave the way Unity developers expect when destroyed objects are involved.

No extra configuration flow is required.Import the package from the Unity Asset Store and let the extension handle the integration.
It is built for standard Unity scripts.The tool is meant to make modern C# syntax usable in normal Unity code without special-case habits.
All platforms are supported.Smooth Operator has support across platforms, including build pipelines.

FAQ

Direct answers.

Why do the null operators fail without this?

Unity has a custom `==` implementation that checks whether the native-side object has been destroyed. The `?.` and `??` operators cannot be overridden, so they cannot participate in that custom behavior.

Does it add meaningful performance overhead?

The overhead is negligible, and the resulting behavior is equivalent to using Unity’s regular overloaded null check in an `if` statement.

Is this only for GameObjects?

The problem is often explained in terms of Unity GameObjects, but the underlying issue is Unity’s object null semantics more broadly. The key point is safe null-operator use with Unity objects.

Do build pipelines still work?

Yes. Build pipelines are supported.

What is the scope of setup?

No extra configuration is needed after import. The package is intended to handle the integration on its own.

What if I just avoid `?.` and `??`?

You can, but the whole point of the tool is to stop writing around the engine limitation when modern C# syntax would otherwise be clearer and less repetitive.

Get Smooth Operator

Use cleaner null syntax without giving up Unity-safe behavior.

Available on the Unity Asset Store.