So I have a simple class (not derived from MonoBehaviour or ScriptableObject) called GameTriggerData. This is basically just a container that defines various information for any event I may want to happen during the game. I read many in via XML, but I also support adding them via the inspector directly in a scene. These manually added ones are attached to my LevelTrigger object.
Problem: Everytime I enter a character or number in an entry, I get an error ‘Unsupported type GameTriggerData’ with NO information in the log. The data serializes fine.
The GameTriggerData class:
[System.Serializable]
public class GameTriggerData
{
public GameTriggerEvent m_TriggerEvent = GameTriggerEvent.None;
public float m_TriggerTime = -1.0f;
public string m_LevelObjectName = "";
public LevelObject m_LevelObject = null;
public string m_String1 = "";
public string m_String2 = "";
public float m_Float1 = 0.0f;
public float m_Float2 = 0.0f;
public int m_Int1 = 0;
public int m_Int2 = 0;
public bool m_Bool1 = false;
public bool m_Bool2 = false;
public Color m_Color = Color.black;
public Transform m_TransformToAttachTo = null;
public Quaternion m_LocalRotation = Quaternion.identity;
public void ClearData()
{
m_String1 = "";
m_String2 = "";
m_Float1 = 0.0f;
m_Float2 = 0.0f;
m_Int1 = 0;
m_Int2 = 0;
m_Bool1 = false;
m_Bool2 = false;
}
}
The LevelTrigger class:
public class LevelTrigger : MonoBehaviour
{
[HideInInspector] public List<GameTriggerData> m_TriggerData = new List<GameTriggerData>();
etc...
}
And finally this is my custom script (just a portion) that handles the data:
So again, just to reiterate: whenever I enter ANY character for ANY entry, I get that ‘Unsupported type GameTriggerData’ every single time. It’s more a nuisance than anything since everything seems to serialize fine.
But I’d appreciate any help in figuring out exactly what’s going on, especially in case there are other, deeper problems, present.
Thank you ArkaneX. Removing and reapplying the component fixed the issue. I’ll mark this as an answer for anyone else that encounters this strange issue.
I was having this same problem and found the idea of manually removing and re-adding the component to each object pretty daunting as I already have a lot of objects with custom field values set. So I wrote the following method for an editor script, which automates the process. It seems to successfully remove and re-add a given component to all objects in a scene (while preserving their field values) and resolve the “unsupported type” error messages.
Note, though, that it uses some undocumented calls to UnityEditorInternal.ComponentUtility and has to do some awkward stuff with prefabs to keep the re-added components from losing their connection to the prefab, so please test carefully in your game before relying on it. If there’s a cleaner way to do it I’d love to know!
// Copies, deletes, and recreates all instances of a component in the scene
// to resolve annoying (but apparently harmless) "unsupported type" errors.
void CleanUpUnsupportedTypeErrorsInScene () {
// Find and replace "Bus" to change the component being worked on
Bus[] components = Resources.FindObjectsOfTypeAll<Bus>();
// We go up to the GameObject level because it's not a good idea to
// destroy components as we iterate over them.
GameObject[] objs = components.Select(component => component.gameObject).ToArray();
foreach (GameObject obj in objs) {
PrefabType pType = PrefabUtility.GetPrefabType(obj);
bool pInstance = pType == PrefabType.PrefabInstance;
bool pNone = pType == PrefabType.None;
// Don't change prefabs themselves, as that will result in duplicate
// copies of the component and other weirdness
if (pInstance || pNone) {
Bus component = obj.GetComponent<Bus>();
UnityEditorInternal.ComponentUtility.CopyComponent(component);
if (pInstance) {
PrefabUtility.DisconnectPrefabInstance(obj);
}
DestroyImmediate(component, true);
if (pInstance) {
// This will bring back the destroyed component
PrefabUtility.ReconnectToLastPrefab(obj);
component = obj.GetComponent<Bus>();
UnityEditorInternal.ComponentUtility.PasteComponentValues(component);
} else { // must be pNone
UnityEditorInternal.ComponentUtility.PasteComponentAsNew(obj);
}
}
}
}
For anyone in the same situation, that doesn’t want to remove the component and add it again, or write a script to do so just for 1 prefab:
I think this happens when a property that was being serialized in a format, changes drastically.
In my case, it was the “Attack” property in a prefab variant.
Previously, I had a class Attack : ScriptableObject which I was referencing in the inspector directly.
I decided to make Attack a standalone class, that doesn’t inherit from anywhere and that’s when I got the
“Unsuppoerted type Attack” error.
What I did was to open the .prefab file in a text editor (Notepad++) and looked for the property Unity is complaining about - Attack, in my case:
I found a serialized property modification called “_attack” and removed it (lines 83 to 87):