• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by MOrlando616 · Sep 09, 2013 at 03:36 PM · editorinspectorserializationunsupported

'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

Comment
stevethorne
Dalsia
Ash-Blue
mattgreggs

People who like this

4 Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ArkaneX · Sep 09, 2013 at 03:52 PM 1
Share

Take a look at this question. Maybe your problem can be fixed the same way?

4 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by MOrlando616 · Sep 09, 2013 at 09:49 PM

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.

Comment
stevethorne
Nairda_Draziw
MrTruth0
kev_pearman
andrei2699
jpgomez13
Dalsia
Ash-Blue
Mario8664
romanpapush
Anisoropos
Dailyalex
captainafk
LiorZana

People who like this

14 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by mactyr · Mar 02, 2014 at 07:20 PM

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

People who like this

1 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by laurG · Oct 15, 2021 at 12:59 PM

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

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


prefabfile.png (79.9 kB)
Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by ATLGAN · Sep 11, 2019 at 02:07 PM

This is mistake error but thanks it's worked.

Date: 11.09.2019 Unity version: 2019.1.7

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make a serialized editor only field 2 Answers

How do I make child classes in a list editable from the Inspector? 1 Answer

Populating list of custom class through inspector 1 Answer

Why doesn't my ScriptableObject save using a custom EditorWindow? 3 Answers

Order of a serializable list not saved correctly using ReorderableList 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges