Search Unity

Bug Different serialization layout

Discussion in 'Scripting' started by Crouching-Tuna, Nov 26, 2020.

  1. Crouching-Tuna

    Crouching-Tuna

    Joined:
    Apr 4, 2014
    Posts:
    82
    So i'm getting these 3 errors

    The offending line is on the last error is:

    Code (CSharp):
    1. static Dictionary<int, DelMonsterBrain> cache;
    2. public static Dictionary<int, DelMonsterBrain> dict {
    3.     get {
    4.         // not loaded yet?
    5.         if(cache == null)
    6.         {
    7.             DelMonsterBrain[] monsters = Resources.LoadAll<DelMonsterBrain>("");            
    8.         }
    9.         return cache;
    10.     }
    11. }
    So as u can see, it's just a lazy load singleton dictionary. The important points are:
    1. I have like 6 other patterns (for items, skills, npc, etc), and they never caused this problem
    2. The script is a ScriptableObject
    3. Between when this error happens and last i checked before it starts, i didnt even change this script (DelMonsterBrain)
    4. The only changes i made were related to Jobs system, completely elsewhere in the codebase
    5. This only happens in build (Windows 64bit, Development build, Script debugging)
    6. For a quick test, i did Debug.Log(DelMonsterBrain.dict.Count); at Start. These 3 errors pops up, but the log prints just fine. So, it's not actually causing any real harm (even tested the build as server, and everything seems to work properly)
    7. I dont use any #ifdef in this script, nor in any members of this script, also no [SerializeField] here either
    8. What is serialization layout anyways? I tried adding more members in this script to test, but the offending byte doesn't change (40, expected 140). Also tried adding variables inside the member classes of this script, no difference

    I've read many other posts regarding similar error, but they all seem unrelated to each other
    The closest is maybe this:https://answers.unity.com/questions/1152311/a-script-behaviour-script-unknown-or-not-yet-loade.html
    These are SOs placed in Resources. Literally the same setup as my 5 other databases

    Any help would be greatly appreciated!
    Cheers
     
    Last edited: Nov 26, 2020
    Filip8429 and martinmungard like this.
  2. Dapeos

    Dapeos

    Joined:
    Jun 27, 2013
    Posts:
    28
    Bump, I am dealing with the same issue. I recently restructured my ecs project to use Scriptable Objects and Addressables. Editor works fine, but when I execute a build it crashes with:
    ."..has a different serialization layout when loading. (Read 32 bytes but expected 92 bytes)
    Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?"
     
    Pawciu, CGDever and martinmungard like this.
  3. djbyrne1

    djbyrne1

    Joined:
    Feb 5, 2014
    Posts:
    3
    I am seeing the exact same issue
     
    CGDever and martinmungard like this.
  4. FuntikStudio

    FuntikStudio

    Joined:
    Sep 29, 2017
    Posts:
    1
    Yep, the same in Unity2019.4.4f1
    Errors going along this line:
    Code (CSharp):
    1. A scripted object (probably MagicInk.Managers.Bootstrap?) has a different serialization layout when loading. (Read 32 bytes but expected 36 bytes)
    2. Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?
    3. (Filename: C:\buildslave\unity\build\Runtime/Serialize/SerializedFile.cpp Line: 2324)
     
    CGDever and martinmungard like this.
  5. Deleted User

    Deleted User

    Guest

    I am also seeing this problem in Unity 2020.3.10f1 without much changing in this spot of the code.
     
  6. EwieElektro

    EwieElektro

    Joined:
    Feb 22, 2016
    Posts:
    45
    Here, me too.... the same issue with 2020.3.11f and "Resources.LoadAll" :/
     
    martinmungard likes this.
  7. unity_bYZN0GC37RBjvA

    unity_bYZN0GC37RBjvA

    Joined:
    Oct 14, 2018
    Posts:
    1
    Hi, same here (A scripted object (probably UnityEngine.UI.Image?) has a different serialization layout when loading Did you #ifdef)
     
    martinmungard likes this.
  8. OMOH98

    OMOH98

    Joined:
    May 19, 2018
    Posts:
    2
    Same here. Unfortunately... If that happen to be a bug, has anyone filed a bug report yet?
     
  9. martinusprim

    martinusprim

    Joined:
    Jul 25, 2019
    Posts:
    11
    Hi, Same problem with Resources.LoadAll in 2021.1.17f1.
     
  10. martinmungard

    martinmungard

    Joined:
    Feb 7, 2018
    Posts:
    5
    I have the same issue... Do anyone have a solution?
     
  11. ItsGonnaBeOk

    ItsGonnaBeOk

    Joined:
    Jul 14, 2016
    Posts:
    21
    Hello everyone.

    I was able to solve such a bug with simple solution - added required assets under sub directory.
    So that Resources.LoadAll<MyScript>("") has transformed into Resources.LoadAll<MyScript>("SomeSubdirectory").

    Why it solved the issue? Well, let me tell you my guess.

    When you build your project, Unity merges all the Resources folders into one internal format that is similar to asset bundle. So every folder basically becomes one.
    Therefore, when you put your assets into root of any Resources folder, it will later share the directory path will all the other assets that are also placed into the root of any other Resources folder.
    In my case, I was loading some prefabs that were initially put into one folder. And the other had some broken assets with invalid serialization layout.
    When Resources system is issued a load request, it most probably iterates over all the possible assets in the specified directory and then check whether it has required component type or not. When it was checking my Resources root, it eventually stumbled upon broken asset and it generated the error, moving on to the next one.
    After I placed my prefabs into sub directory and specified it in LoadAll method - the system started to check only that folder, and completely ignored the broken assets.

    Whelp, thats my guess, anyway.

    Hope it helps.
     
  12. jchowdown-asla

    jchowdown-asla

    Joined:
    May 10, 2017
    Posts:
    26
    We're having this problem with assets loaded from bundles.

    The referenced script (Unknown) on this Behaviour is missing!


    would it kill Unity to print out the name/path of the gameobject in question?
     
    bluescrn, AldeRoberge and Thaina like this.
  13. PieterAlbers

    PieterAlbers

    Joined:
    Dec 2, 2014
    Posts:
    247
    Thanks for sharing - this helped me!
     
  14. SeSexy3

    SeSexy3

    Joined:
    Oct 31, 2018
    Posts:
    1
    same in Unity2021.2.0.f1
     
  15. ManeFrismos

    ManeFrismos

    Joined:
    May 22, 2018
    Posts:
    1
    I had the same problem, it turned out there was a problem with scriptable objects (I named my class with a typo). Check your scriptable objects, if the script is "none", then the problem is probably there (see screenshots)
     

    Attached Files:

    Northmaen likes this.
  16. odaimoko

    odaimoko

    Joined:
    Jun 28, 2020
    Posts:
    9
    I'm providing a solution since here since this is the first post when I google this 'bug'.
    I encounter this problem using Addressables. I also wrap some serialized fields with UNITY_EDITOR, which it claims to change the serialization layout.

    What I did is to add another define symbol and use it to wrap around the fields that i need in the editor but not runtime, such as ENABLE_ADDITIONAL_SERIALIZED_FIELDS, not UNITY_EDITOR.
    When I build the player, I remove this symbol manually and then build Addressables. It solved the issue.
    I don't if removing symbols before building can be automated. Did not try it since I don't use CI/CD at the present, but if it can, it would be much greater.
     
  17. dynamicvoltagegames

    dynamicvoltagegames

    Joined:
    Apr 15, 2019
    Posts:
    24
    This could be user error, but it's also 100% a Unity bug that can happen. I had a project that was building just fine. Then, without any changes at all, it started happening and there's no way to fix it. It's just Unity deciding to randomly break your project, which is common.