Unity Option

About

Unity Option is a package I created because I was missing a way to clearly convey that some serialized fields may be optional. For example: A 'Car' component might have a reference to a spare tire gameobject that lives in the hierarchy. Of course not all cars have a spare tire so the reference could be null. This is a problem because the user of your spare tire in code does not know that the value could be null and may cause an error at runtime (although in this example it's more obvious). The Option type solves this problem by enforcing the user to check if the value is present before accessing it.

I of course did not invent the concept of an option type. All I did was make it more accessible to people who want to use it in the Unity editor. It is especially powerful when combined with a project validation tool like the Odin Validator. (More information about this on the GitHub repo).


Availability

You can find the package on my GitHub, licensed under MIT.

image
image