Search Issue Tracker

Fixed in 2017.1.0f3

Votes

0

Found in

2017.1.0b1

Issue ID

902037

Regression

Yes

Project sometimes fail to build due to different serialization order in Editor and Player

Serialization

-

Reproduction steps:
1. Open project attached (PartialClassBuild.zip).
2. Build it on standalone player.

Expected result: It will be built successfully.
Actual result: Building stops, output from console: (NOT ALWAYS!)
Error: "Type '[Assembly-CSharp]Player' has an extra field 'FieldTwo' of type 'System.Int32' in the player and thus can't be serialized (expected 'FieldOne' of type 'System.Int32')"
Error: Type '[Assembly-CSharp]Player' has an extra field 'FieldThree' of type 'System.Int32' in the player and thus can't be serialized (expected 'FieldOne' of type 'System.Int32')
Error: "Fields serialized in Editor, class 'Player'
'FieldOne' of type 'System.Int32'
'FieldTwo' of type 'System.Int32'
'FieldThree' of type 'System.Int32'"
Error: "Fields serialized in target platform, class 'Player'
'FieldTwo' of type 'System.Int32'
'FieldThree' of type 'System.Int32'
'FieldOne' of type 'System.Int32"
Error: "Error building player because script class layout is incompatible between the editor and the player."

Note: This does not appear all the time. If it is not reproducible from first time, just makes some changes (add space) in Player.cs.

Reproduced on: 2017.1.0a3, 2017.1.0b1.
Works fine on: 5.6.0p1.
Regression introduced in 2017.

Comments (14)

  1. 9defffbd9ffa606b2add9ad9769fbe19?d=mm

    AlejandroBA7

    Feb 08, 2020 00:44

    The error also appears in Unity 2019.3.0f6

  2. 61fbc03b26cf0592b724b69b117b86a1?d=mm

    sandeepkiks

    Jan 17, 2020 08:59

    This issue again happens in Unity 2019.3.0f5

  3. 81948edcf80ef6c9093726cf4922f80f?d=mm

    fsedarkalex

    Dec 14, 2019 12:04

    Still happening with 2019.2.16f1. I am just uploading a bug report.

  4. E16554d28a31b0ccacff72e795354f1c?d=mm

    Superniquito

    Oct 09, 2019 02:03

    This issue is happening in 2019.3.0b6, and after I removed the asset store package that was throwing the error I got it again in one of my own scripts.

  5. F1f8fa4fe470197ce70cefa3cb242a10?d=mm

    Paul_Bronowski

    Jun 12, 2019 05:27

    I was incorrect. unsealing the classes did not workaround the problem. It appears to be intermittent. Still looking for a workaround.

  6. F1f8fa4fe470197ce70cefa3cb242a10?d=mm

    Paul_Bronowski

    Jun 07, 2019 06:03

    The problem appears to be related to serialized fields in sealed partial classes. One possible workaround, which seems to resolve the build error, is to remove the sealed keyword.

    Again, I'm on 2018.4.0f1 and my failing case looks like...

    // There are 4 files that make this partial class
    // None contain public fields, all contain [SerializeField] private fields
    public sealed partial class LoaderService
    : ServiceMonoBehaviour<LoaderService>
    {
    }

    // No serialized fields here
    public abstract class ServiceMonoBehaviour<TService> :
    ServiceMonoBehaviour,
    IService<TService>
    where TService : ServiceMonoBehaviour<TService>
    {
    }

    // No serialized fields here
    public abstract class ServiceMonoBehaviour
    : MonoBehaviour,
    IService
    {
    }

    Cleaning all intermediates/temps does not resolve the build error, nor does building in VS before the command-line build. Note that ProBuilder NuGet package also has the problem in several classes...

    namespace UnityEngine.ProBuilder
    {
    public sealed partial class ProBuilderMesh

  7. F1f8fa4fe470197ce70cefa3cb242a10?d=mm

    Paul_Bronowski

    Jun 07, 2019 03:25

    FWIW, I'm seeing this with 2018.4.0f1. Same partial class problem with one of my classes and a nuget package, on clean x64 standalone command-line build. Trying to work around it.

  8. E1261df3165c773359c765dfaf806b49?d=mm

    h0lmie

    May 20, 2019 14:28

    Issue is present in 2018.4.0f1 LTS as well. Just updated from 2018.1.6f1 which did not have the issue.

    Restarting Unity fixes it, and allows commandline gradlebuilding just fine. Issue seems to reoccur if scripting define symbols get modified, or recompilation in general.

  9. 6196fce4310fd9a56d6c0498d337c8a0?d=mm

    imuzzolini

    Jan 09, 2019 15:34

    I can confirm that is still present in 2018.2.12f1.

    I was able to reproduce the issue as follows:

    - open the project with Unity Ediror
    - build
    - exit the Editor
    - make a modification with another text editor to a C# class that is marked with the [Serializable] attribute (e.g., inverting the order of 2 public properties)
    - build the project in batch mode (i.e., C:\Unity\2018.2.12\Editor\Unity.exe -batch -projectPath D:\path\to\project\issue...)
    - build fails

  10. 48e90eef596fdd4eda77b966a18d8ea8?d=mm

    vizgl

    Dec 10, 2018 21:23

    Same here. If I build project from editor all works fine, but if I use command line batch build, then build process finished with errors like:
    Fields serialized in target platform, class 'UnityEngine.Timeline.TrackAsset'

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.