Search Unity

(Case 1122461) Deserialization Problem of ScriptableObject containing Asset References

Discussion in 'Addressables' started by MNNoxMortem, Jan 30, 2019.

  1. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    Error:
    Code (CSharp):
    1. A scripted object (probably SceneReference?) has a different serialization layout when loading. (Read 92 bytes but expected 164 bytes).
    2. Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?
    Code (CSharp):
    1.     public class SceneReference : ScriptableObject
    2.     {
    3.         public AssetReference AssetReference;
    4.         public string DisplayName;
    5.         public string SceneName;
    6.         public string Uuid;
    7.     }
    SceneReference has no #if but AssetReference has some.

    That error message does not look helpful. The size of SceneReference should not change when the size of AssetReference changes. The only thing which comes to my mind is that the Addressable Asset System has problems with compression and that the asset is loaded compressed and then it tries to deserialize it without uncompressing it.

    Edit: Should have noted: This only happens in a WebGL build and because that is IL2CPP based I'ved added a link.xml to include the whole assembly SceneReference resides in to avoid any Stripping.
     
    Last edited: Jan 30, 2019
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Thanks for letting us know, I've added a ticket to our system.
     
  3. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    @unity_bill I would like to provide some more helpful information if I find out why and how this happens. This issue is mightily strange and breaks our CI/CD as the builds made via CD all show this error and no addressable can be successfully deserialized. However on my local dev machine (same platform, same build target, same OS, same profile, both times clean player content then build player content) this does not happen.

    Both machines are in the same network and use the same Cache Server (node.js based version running on the CI/CD machine). Of course both use the same Unity version.

    I will try to go through the steps I do on my machine on the CI/CD machine by hand and try to find out why there is a different serialization layout but so far I have not the slightest clue (no code changes!)
     
    unity_bill likes this.
  4. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    Okay... it happens on both machines, not only the CI machine. Some builds work. Some don't.
     
  5. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    Okay - two consecutive builds without a change on my side in between: One loads - one fails. I assume it is A) Cache related or B) related to files in the folder it builds the addressables into. That is the only thing I know that is different betwen two builds. Both were made with Clean Player Content > Build Player Content.
     
  6. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    @unity_bill looks like this Case is actually related to Case 1117939. After failing several builds in a row I reimported scripts and assets manually and the next build worked.
     
  7. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    @unity_bill as we got the mail, that the bug was reproduced but no fixed version yet. Is there any fixed in version known already? We are still heavily hindered by this in Unity 2018.3.12f1 which was just released.
     
  8. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    @unity_bill Looking at Asset Reference and the forum post here I'd guess one of the problems is that we use AssetReferences inside of ScriptableObjects because of

    \Library\PackageCache\com.unity.addressables@0.6.7-preview\Runtime\AssetReference.cs

    Code (CSharp):
    1. #if UNITY_EDITOR
    2.         [FormerlySerializedAs("m_cachedAsset")]
    3.         [SerializeField]
    4.         Object m_CachedAsset;
    5. #endif
    and the other
    Library\PackageCache\com.unity.postprocessing@2.1.4\PostProcessing\Runtime\PostProcessLayer.cs
    Code (CSharp):
    1. #if UNITY_EDITOR
    2.         // UI states
    3.         [SerializeField] bool m_ShowToolkit;
    4.         [SerializeField] bool m_ShowCustomSorter;
    5. #endif
    (Although we do not use PostProcessLayer ourself in a ScriptableObject but I assume the PP package does itself)

    Although this is not `Serializable` but `SerializeField`, I assume both affect the serialized binary layout.
     
  9. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    yes, that is the problem, and it's fixed in the upcoming 0.7.x release.
     
    MNNoxMortem likes this.