Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

Bug Different serialization layout

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

  1. Crouching-Tuna

    Crouching-Tuna

    Joined:
    Apr 4, 2014
    Posts:
    80
    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
    martinmungard likes this.
  2. Dapeos

    Dapeos

    Joined:
    Jun 27, 2013
    Posts:
    20
    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?"
     
    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. AbsurdAndy

    AbsurdAndy

    Joined:
    Dec 6, 2019
    Posts:
    24
    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:
    42
    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:
    10
    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.
     
    PieterAlbers and Crouching-Tuna like this.
  12. jchowdown-asla

    jchowdown-asla

    Joined:
    May 10, 2017
    Posts:
    23
    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?
     
    Thaina likes this.
  13. PieterAlbers

    PieterAlbers

    Joined:
    Dec 2, 2014
    Posts:
    196
    Thanks for sharing - this helped me!
     
unityunity