Search Unity

Building failes after Update to 2017.3

Discussion in 'Editor & General Support' started by Ecocide, Jan 23, 2018.

  1. Ecocide

    Ecocide

    Joined:
    Aug 4, 2011
    Posts:
    293
    Hi,

    unfortunately after upgrading to the newest version I cannot build anymore.

    This is the error that is showing:

    It usually gives more information about the class instead showing MonoBehaviour. There is also no class where I tried to overwrite the System.Type type field. The exact same project builds in Unity 5.6.3 which is what I still use for development.

    Is there any chance I could find out what file is producing this error? Reading the Editor.log did not help unfortunately.

    Thanks!
     

    Attached Files:

  2. Ecocide

    Ecocide

    Joined:
    Aug 4, 2011
    Posts:
    293
    Ok, I found a solution.

    Obviously this is not supported:

    Code (csharp):
    1.  
    2.     public enum VehicleType
    3.     {
    4.         Car,
    5.         Truck,
    6.         Bike,
    7.         Ambulance
    8.     }
    9.     public abstract class Vehicle : MonoBehaviour
    10.     {
    11.         [SerializeField]
    12.         protected VehicleType type;
    13.     }  
    14.  
    If I rename the variable type to something else, it works. There is no type variable in a child class, btw! So the error is completely wrong in this case.

    Note: This is only in one of the newer versions (2017.3 tested)
     
  3. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,281
    When serializing a MonoBehaviour there is also a lot of internal fields. If you use the same name then the above error will occur. `type` sounds like a name that would clash. If you use text serializing and then open the file you will see the names.
    A quick check shows that the type name is used.

    Code (CSharp):
    1. MonoBehaviour:
    2.   m_ObjectHideFlags: 0
    3.   m_PrefabParentObject: {fileID: 0}
    4.   m_PrefabInternal: {fileID: 0}
    5.   m_GameObject: {fileID: 0}
    6.   m_Enabled: 1
    7.   m_EditorHideFlags: 0
    8.   m_Script: {fileID: 11500000, guid: 26c27b7a97ae7cd47ac063fc4ede4bf9, type: 3}
    9.   m_Name: Default Locale Selector
    10.   m_EditorClassIdentifier:
    m_Script: {fileID: 11500000, guid: 26c27b7a97ae7cd47ac063fc4ede4bf9, type: 3}

    I believe we did make some core changes to the MonoBehaviour base class and the introduction of the property type is likely one of them.

    It sucks that we broke your project like this but it should be possible to fix this by changing the name and then using the FormerlySerializedAsAttribute.
     
  4. Ecocide

    Ecocide

    Joined:
    Aug 4, 2011
    Posts:
    293
    Hi Karl, thanks for the help. But shouldn't the field type still work if it is something else than a System.Type type field?
    Renaming indeed fixed this. Of course this is not a big deal, the problem was just to find out what's the issue, because it seems that if you have an abstract class it won't tell you the name of the class but instead says "Base(MonoBehaviour)" which is not very helpful.

    What's interesting though, I tried to replicate this in a fresh project and there was no error at all. Same scripts, just deleted the methods)... I also created that project in an older version of Unity and upgraded that project to 2017.3, but still no error.
    So I think this is just a very rare bug (that fortunately could easily be fixed). So thanks again for the help!
     
    karl_jones likes this.