'Unsupported type' error in custom editor script

Hello,

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:

if( m_Target.m_TriggerData != null )
		{
			EditorGUILayout.BeginVertical();
			
			for( int i = 0; i < m_Target.m_TriggerData.Count; ++i )
			{				
				if( !Utilities.GameTriggerGUI( m_Target.m_TriggerData[ i ] ) )
				{
					m_Target.m_TriggerData.RemoveAt( i );
					--i;
				}
				
				GUILayout.Space( 6 );
				GUILayout.Box( "", GUILayout.ExpandWidth( true ), GUILayout.Height( 1 ) );
				GUILayout.Space( 6 );
			}
			
			EditorGUILayout.EndVertical();
		}
		
		GameTriggerEvent newTriggerEvent = (GameTriggerEvent)EditorGUILayout.EnumPopup( GameTriggerEvent.None, GUILayout.Width( 260.0f ) );
		if( newTriggerEvent != GameTriggerEvent.None )
		{
			GameTriggerData dataToAdd = new GameTriggerData();
			dataToAdd.m_TriggerEvent = newTriggerEvent;
			m_Target.m_TriggerData.Add( dataToAdd );
			EditorUtility.SetDirty( m_Target );
		}

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.

Thanks!
-Matt

1 Like

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);
			}
		}
	}
}

This is mistake error but thanks it’s worked.

Date: 11.09.2019
Unity version: 2019.1.7

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):

Saved the file, opened Unity and the error was gone!

!!! - in case it’s not a prefab, open the scene in which the object is saved and look for the object by name