How to know if a type can be serialized in inspector

How to know if some type can be shown in the inspector? Those types that have a GUI field that can be shown in the Inspector.

var type = parameters*.ParameterType; // https://learn.microsoft.com/en-us/dotnet/api/system.reflection.parameterinfo.parametertype?view=net-6.0#system-reflection-parameterinfo-parametertype*

if(type.Equals(typeof(bool))) Debug.Log(“”);
else if(type.Equals(typeof(double))) Debug.Log(“”);
else if(type.Equals(typeof(float))) Debug.Log(“”);
else if(type.Equals(typeof(int))) Debug.Log(“”);
else if(type.Equals(typeof(long))) Debug.Log(“”);
else if(type.Equals(typeof(string))) Debug.Log(“”);
else if(type.Equals(typeof(AnimationCurve))) Debug.Log(“”);
else if(type.Equals(typeof(Bounds))) Debug.Log(“”);
else if(type.Equals(typeof(BoundsInt))) Debug.Log(“”);
else if(type.Equals(typeof(Color))) Debug.Log(“”);
else if(type.Equals(typeof(Enum))) Debug.Log(“”);
else if(type.Equals(typeof(UnityEngine.Object))) Debug.Log(“”);
else if(type.Equals(typeof(Quaternion))) Debug.Log(“”);
else if(type.Equals(typeof(Rect))) Debug.Log(“”);
else if(type.Equals(typeof(RectInt))) Debug.Log(“”);
else if(type.Equals(typeof(Vector2))) Debug.Log(“”);
else if(type.Equals(typeof(Vector2Int))) Debug.Log(“”);
else if(type.Equals(typeof(Vector3))) Debug.Log(“”);
else if(type.Equals(typeof(Vector3Int))) Debug.Log(“”);
else if(type.Equals(typeof(Vector4))) Debug.Log(“”);

This question can’t be answered conclusively as our Captain mentioned in the comments above :slight_smile:

You get a rough overview in the documentation. Where things get fuzzy is when you have a “SerializeReference” field which can serialize some things that you can’t serialize normally. Also the ISerializationCallbackReceiver may implement pre / post processing which may allow certain data to be serialized. However you can’t really tell what data is actually serialized without looking at the actual serialized data.

You also said “if some type can be shown in the inspector”. While this usually means the type has to be serializable, custom editors can show things in the inspector that are not serialized. So your question gets even more ambiguous.

As Captain Pineapple already said, this sounds like an XY problem. For some reason you want to know a way to know or to get a list of types that can be serialized which is a pretty odd question. This is a bit like asking for a list of animals with two four legs. There are always some species which may count as two, four or six legged depending on the category. The question is what do you need this information for? You could now start compiling an endless growing list of animals which may fit this category and in the end you’re only interested in mammals because you have two different animations for giving birth depending on the number of legs.

So the question is: What do you need that information for?