Binary Impact @binaryimpact.de · Mar 26

#CodingTips In #csharp, the null coalescing operator (??) is used to simplify null checks and provide a default value. In our example we also used ? to make a non nullable to a nullable type. #UnityTips #GodotTips #indiedev #gamedev

7 likes 2 replies

?

Replies

Doctaku · Mar 26

You can also use it to assign a value if an object is null like this: number ??= 42;

GamingGameDev (He/Him) 😷🇵🇸 · Mar 27

Caution, this doesn't work with certain Unity types (they override the equality operator to have "== null" return true for unassigned object references, but they aren't actually null at runtime)