Nullable struct

Why can’t I create a nullable struct in unity c#?

Vector3 can be a nullable type, but when I want to have a nullable struct of my own mono.exe just crashes and Unity does not compile.

Is there a work around for this (except to make the struct a class)?

I am talking about Nullable<T>
Nullable<Vector3> or Vector3? works,
but Nullable<MyStruct> or MyStruct? makes the mono compiler crash.

So, you can’t do it because the Unity mono compiler doesn’t support it. This is annoying as it is a feature that SHOULD be supported all the way back to 2.0 according to the MSDN pages:

My hack around it is thus:

#if UNITY_EDITOR // really a check for unity environment
		Image GetImage(string filename,Rect<int> source, Action<Image> loadedCB=null);
		Image GetImage(string filename,object nullcatcher, Action<Image> loadedCB=null);
#else
		Image GetImage(string filename,Rect<int>? source=null, Action<Image> loadedCB=null);
#endif

As it happens this interface defines an injected platform specific dependency anyway so my Unity one will just be ugly and have to
implement both methods.

The second method will check nullcatcher for null and throw a fit if anything else is passed in. Not ideal but it does keep the rest of my code untouched.

Types (struct, int, float etc) can’t be null.

You can’t set a Vector3 to null in Unity either.
If you mean Vector3.zero, that is not a null, but just a way to set x, y and z to 0.

Why do you want to have your struct set to null, anyway?