Search Unity

script class layout is incompatible between the editor and the player

Discussion in 'Editor & General Support' started by sloopidoopi, Dec 28, 2012.

  1. sloopidoopi

    sloopidoopi

    Joined:
    Jan 2, 2010
    Posts:
    244
    Hi ,
    I have a problem with a script migrating from Unity 3 to version 4.
    My script has some preprocessor directives for Platform Dependent Compilation.
    On Windows and in the Editor i override the existing UnityEngine.Touch class with a custom class. On IOS i use the original class from Unity.
    Until now (Unity 3.5) I had no compilation problems, but with Unity 4.0 when I try to Build for IOS I get some compilation errors:
    Code (csharp):
    1.  
    2. Type 'XTInputManager' has an extra field 'activeInputTouches' of type 'System.Collections.Generic.List<UnityEngine.Touch>' in the player and thus can't be serialized
    3. UnityEditor.HostView:OnGUI()
    4.  
    5. Type 'XTTouchFrameData' has an extra field 'touch' of type 'UnityEngine.Touch' in the player and thus can't be serialized (expected 'hit' of type 'UnityEngine.RaycastHit')
    6. UnityEditor.HostView:OnGUI()
    7.  
    8. Error building player because script class layout is incompatible between the editor and the player.
    9.  
    Don't know what the problem is right now, as it works in the editor, so it can't be a problem with overriding the existing class.
    It seems to me that the Implementation of Unity has changed.
    Any hints are welcome.
     
  2. RazorCut

    RazorCut

    Joined:
    May 7, 2009
    Posts:
    393
    Those errors seem to suggest that you have some serializable member variables inside some preprocessor directives. Unity no like those.
     
    neilsarkar and John-Gray like this.
  3. sloopidoopi

    sloopidoopi

    Joined:
    Jan 2, 2010
    Posts:
    244
    I fixed the problem with using the [NonSerialized] attribute on the fields that causing the errors.
     
    salvolannister likes this.
  4. salvolannister

    salvolannister

    Joined:
    Jan 3, 2019
    Posts:
    50
    Also for me adding [System.NonSerialized] on the attribute causing the problems solved the issue. I still wonder why this error is caused, in my case I am using assembly definition files.

    I wonder if some references I added there caused the problem, but I'd like some expert to say more about this issue
     
  5. Qazi_MinorBugs

    Qazi_MinorBugs

    Joined:
    Jul 7, 2021
    Posts:
    2
    for anyone in future
    Delete those scripts
    and restore from recycle bin
     
    Faikus likes this.
  6. eduardofreire

    eduardofreire

    Joined:
    Jan 24, 2022
    Posts:
    6
    Being more specific, you can only reimport the script file that has the error. Just fixed for me, and it was a script that had nothing to do with GUI.

    But it happend when build for android.
     
  7. Cris_2013

    Cris_2013

    Joined:
    Nov 25, 2017
    Posts:
    39
    I've just migrated from Unity 2019 to Unity 2022, and I am getting this error.
    I've added a public float to an scriptable object and I got this error, so I removed it. Then I added a public float and a public Vector3 to a class (which is used in many prefabs) and I get this error again, I fix it by using [System.NonSerialized] but it seems to me that whenever I add a public variable, Unity doesn't update the prefabs properly and pops this error.
    Is there any way to "clean" the prefabs or solve this issue?

    Many thanks.
     
  8. Cris_2013

    Cris_2013

    Joined:
    Nov 25, 2017
    Posts:
    39
    I've managed to fix the issue, it seems some old data or something was left somewhere causing trouble. I did what it is mentioned in this forum and that worked:
    https://issuetracker.unity3d.com/is...on-order-in-editor-and-player?page=1#comments

    So basically:
    - uninstall all unity versions
    - uninstall unity hub
    - delete temp and appdata unity files
    - remove unity keys from registry under Computer\HKEY_CURRENT_USER\SOFTWARE

    After reinstalling the errors are gone …

    I hope it helps.
     
  9. Wappenull

    Wappenull

    Joined:
    Oct 29, 2013
    Posts:
    51
    Hi Internet travelers and lurkers.
    I got 'Error building player because script class layout is incompatible between the editor and the player.' when building my asset bundle.
    upload_2022-9-6_17-56-49.png

    This happen after upgrading 2022.1.9 -> 2022.1.15 some of the official package (InputSystem) also version up in the process, and the culprit module name that came up in error message was those InputSystem!
    But I can confirm that my build was ok before the upgrade.

    The problem is now fixed
    ,
    I thought I would share it here, this are my steps:
    1. The panic command "Assets -> Reimport All" DID NOT WORK.
    2. I closed the editor. Delete "objs" and "Library" folders inside my project. (Near the Assets folder)
    3. Wait for full import again. I decided to take a break and read bunches of Manga chapters. It was very productive day!
    4. After sometime, it is finished. I proceed to build my asset bundle again. and no more error.
    Looks like there are lingering script cache or assembly cache somewhere inside that Library folder which could not be cleared even if doing lite recompile or "Reimport All" command.

    28 Sep 2022: Small addition
    Looks like asset bundle building process is dependent on main player increment building (or whatsoever) building the whole player again first then proceed to build the asset bundle via "AssetBundle Browser" window (it is part of extra package of the same name) seems to work.

    upload_2022-9-28_17-7-49.png
    In short, if you get such error like above from building asset bundle, rebuild the player again, then proceed with building asset bundle. If all else failed try cleaning "objs" and "Library" as bove.
     

    Attached Files:

    Last edited: Sep 28, 2022
  10. nnsashann

    nnsashann

    Joined:
    Aug 10, 2018
    Posts:
    3
    Remove project from Unity Hub, rename Project folder, add project to Unity Hub, run - profit