Search Unity

Serializing managed objects in SubScenes seems to be broken in 0.2 (with attached example project)

Discussion in 'Entity Component System' started by Zec_, Nov 24, 2019.

  1. Zec_

    Zec_

    Joined:
    Feb 9, 2017
    Posts:
    148
    I'm encountering some weird issues with serialization of managed data/object references in SubScenes.

    In Entities 0.1, I used to be able to serialize references to assets in SharedComponentDatas, but that no longer works in Entities 0.2. I've also tried out the new managed components, but those also cause similar issues.

    When I run this in Entities 0.2.0 preview.18 with unity version 2019.3.0b12, there's no information or errors logged during SubScene conversion (not in the editor log either), but after conversion the SubScene won't load. When it tries to load, it prints a single error about the entity header being missing. The error looks like this:
    Code (CSharp):
    1. Loading Entity Scene failed because the entity header file could not be found: 46de8bc0b82483142a499143e1e476fb
    I've been debugging the internal code as much as I can, but can't find a cause. I've verified that the entity header file in the library cache doesn't show up after conversion. I can't seem to find where the asynchronous serialization is done though, as breakpoints in the regular internal WriteEntityScene functions doesn't work and adding logs in there doesn't seem to print anything (neither in editor nor in the editor log).

    Edit: I've now properly reported this in the bug tracker with case number 1201070

    Regarding the Attached Sample Project
    I've been able to reproduce this in a very small scale project that I'm attaching here. In the attached project, open SampleScene and wait for the SubScenes to import. After import, you should see the errors I'm talking about. You should also be able to see that no entities spawn in the Entity Inspector for the two problematic SubScenes.

    In the scene, there's three SubScenes:
    • SimpleSubScene - just a sanity check subscene that shows that they actually work and does cause entities to spawn in the editor world.
    • SharedComponentReference - using the old style shared component datas to reference a ScriptableObject. Causes the error.
    • ManagedComponentReference - using the new managed component datas to reference a ScriptableObject. Causes the error.
    The project is made using 2019.3.0b12 and Entities 0.2.0 preview.18

    Additional Notes
    Also noteworthy is that on a couple rare occasions when I've been trying out things related to this, I've gotten an omnious warning that sounds like it could be related. It occurs very rarely though, and I can't seem to find out how to reproduce it:
    Code (CSharp):
    1. Error when processing 'AsyncLoadSceneJob(VirtualArtifacts/Extra/05/05943b4ff7b90aac62b03ba4eea1ab85.0.entities)': System.ArgumentException: Requested value outside bounds of UnsafeAppendOnlyBuffer. Remaining bytes: {Buffer->Size - m_Offset} Requested: {structSize}
    2.   at Unity.Collections.LowLevel.Unsafe.UnsafeAppendBuffer+Reader.CheckBounds (System.Int32 structSize) [0x00015] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.collections@0.2.0-preview.13\Unity.Collections\UnsafeAppendBuffer.cs:190
    3.   at Unity.Collections.LowLevel.Unsafe.UnsafeAppendBuffer+Reader.ReadNext[T] (T& value) [0x00007] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.collections@0.2.0-preview.13\Unity.Collections\UnsafeAppendBuffer.cs:196
    4.   at Unity.Entities.Serialization.PropertiesBinaryReader.BeginCollection[TProperty,TContainer,TValue] (TProperty property, TContainer& container, TValue& value, Unity.Properties.ChangeTracker& changeTracker) [0x00032] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.entities@0.2.0-preview.18\Unity.Entities\Serialization\BinaryWriter.cs:450
    5.   at Unity.Properties.PropertyVisitor.TryVisitCollectionWithAdapters[TProperty,TContainer,TValue] (TProperty property, TContainer& container, TValue& value, Unity.Properties.ChangeTracker& changeTracker) [0x00057] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.properties@0.10.3-preview\Runtime\Unity.Properties\PropertyVisitor.cs:148
    6.   at Unity.Properties.PropertyVisitor.VisitCollectionProperty[TProperty,TContainer,TValue] (TProperty property, TContainer& container, Unity.Properties.ChangeTracker& changeTracker) [0x00021] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.properties@0.10.3-preview\Runtime\Unity.Properties\PropertyVisitor.cs:85
    7.   at Unity.Properties.Reflection.ReflectedPropertyBag`1+CollectionPropertyProxy`2[TContainer,TProperty,TValue].Accept[TVisitor] (TContainer& container, TVisitor& visitor, Unity.Properties.ChangeTracker& changeTracker) [0x00000] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.properties@0.10.3-preview\Runtime\Unity.Properties\Reflection\ReflectedPropertyBag.cs:32
    8.   at Unity.Properties.Reflection.ReflectedPropertyBag`1[TContainer].Accept[TVisitor] (TContainer& container, TVisitor& visitor, Unity.Properties.ChangeTracker& changeTracker) [0x00006] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.properties@0.10.3-preview\Runtime\Unity.Properties\Reflection\ReflectedPropertyBag.cs:77
    9.   at Unity.Properties.PropertyContainer.Visit[TContainer,TVisitor] (TContainer& container, TVisitor& visitor, Unity.Properties.ChangeTracker& changeTracker) [0x00075] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.properties@0.10.3-preview\Runtime\Unity.Properties\PropertyContainerVisit.cs:68
    10.   at Unity.Properties.PropertyContainer.Visit[TContainer,TVisitor] (TContainer& container, TVisitor visitor, Unity.Properties.ChangeTracker& changeTracker) [0x00001] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.properties@0.10.3-preview\Runtime\Unity.Properties\PropertyContainerVisit.cs:51
    11.   at Unity.Properties.PropertyVisitor.TryVisitContainerWithAdapters[TProperty,TContainer,TValue] (TProperty property, TContainer& container, TValue& value, Unity.Properties.ChangeTracker& changeTracker) [0x0006b] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.properties@0.10.3-preview\Runtime\Unity.Properties\PropertyVisitor.cs:125
    12.   at Unity.Properties.PropertyVisitor.VisitProperty[TProperty,TContainer,TValue] (TProperty property, TContainer& container, Unity.Properties.ChangeTracker& changeTracker) [0x00032] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.properties@0.10.3-preview\Runtime\Unity.Properties\PropertyVisitor.cs:55
    13.   at Unity.Properties.Reflection.ReflectedPropertyBag`1+PropertyProxy`2[TContainer,TProperty,TValue].Accept[TVisitor] (TContainer& container, TVisitor& visitor, Unity.Properties.ChangeTracker& changeTracker) [0x00000] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.properties@0.10.3-preview\Runtime\Unity.Properties\Reflection\ReflectedPropertyBag.cs:20
    14.   at Unity.Properties.Reflection.ReflectedPropertyBag`1[TContainer].Accept[TVisitor] (TContainer& container, TVisitor& visitor, Unity.Properties.ChangeTracker& changeTracker) [0x00006] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.properties@0.10.3-preview\Runtime\Unity.Properties\Reflection\ReflectedPropertyBag.cs:77
    15.   at Unity.Properties.PropertyContainer.Visit[TContainer,TVisitor] (TContainer& container, TVisitor& visitor, Unity.Properties.ChangeTracker& changeTracker) [0x00075] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.properties@0.10.3-preview\Runtime\Unity.Properties\PropertyContainerVisit.cs:68
    16.   at Unity.Properties.PropertyContainer.Visit[TContainer,TVisitor] (TContainer& container, TVisitor visitor, Unity.Properties.IVersionStorage versionStorage) [0x00009] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.properties@0.10.3-preview\Runtime\Unity.Properties\PropertyContainerVisit.cs:22
    17.   at Unity.Entities.Serialization.BoxedProperties+ReadBoxedClassForwarder.Invoke[T] () [0x00016] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.entities@0.2.0-preview.18\Unity.Entities\Serialization\BinaryWriter.cs:38
    18.   at Unity.Properties.PropertyBag`1[TContainer].Cast[TCallback] (TCallback& callback) [0x00001] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.properties@0.10.3-preview\Runtime\Unity.Properties\IPropertyBag.cs:38
    19.   at Unity.Entities.Serialization.BoxedProperties.ReadBoxedClass (System.Type type, Unity.Entities.Serialization.PropertiesBinaryReader reader) [0x0001c] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.entities@0.2.0-preview.18\Unity.Entities\Serialization\BinaryWriter.cs:58
    20.   at Unity.Entities.Serialization.SerializeUtility.ReadSharedComponents (Unity.Entities.ExclusiveEntityTransaction manager, Unity.Entities.Serialization.PropertiesBinaryReader managedDataReader, Unity.Collections.NativeArray`1[T] sharedComponentRecordArray) [0x00022] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.entities@0.2.0-preview.18\Unity.Entities\Serialization\SerializeUtility.cs:600
    21.   at Unity.Entities.Serialization.SerializeUtility.DeserializeWorld (Unity.Entities.ExclusiveEntityTransaction manager, Unity.Entities.Serialization.BinaryReader reader, System.Object[] unityObjects) [0x00119] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.entities@0.2.0-preview.18\Unity.Entities\Serialization\SerializeUtility.cs:82
    22.   at Unity.Scenes.AsyncLoadSceneOperation+AsyncLoadSceneJob.Execute () [0x00057] in C:\Projects\SerializationIssues\SerializationIssues\Library\PackageCache\com.unity.entities@0.2.0-preview.18\Unity.Scenes.Hybrid\AsyncLoadSceneOperation.cs:99
    23. UnityEngine.Debug:LogWarning(Object)
    24. Unity.Debug:LogWarning(String) (at Library/PackageCache/com.unity.entities@0.2.0-preview.18/Unity.Entities/Stubs/Unity/Debug.cs:15)
    25. Unity.Scenes.SceneSectionStreamingSystem:UpdateLoadOperation(AsyncLoadSceneOperation, World, Entity) (at Library/PackageCache/com.unity.entities@0.2.0-preview.18/Unity.Scenes.Hybrid/SceneSectionStreamingSystem.cs:370)
    26. Unity.Scenes.SceneSectionStreamingSystem:ProcessActiveStreams() (at Library/PackageCache/com.unity.entities@0.2.0-preview.18/Unity.Scenes.Hybrid/SceneSectionStreamingSystem.cs:273)
    27. Unity.Scenes.SceneSectionStreamingSystem:OnUpdate() (at Library/PackageCache/com.unity.entities@0.2.0-preview.18/Unity.Scenes.Hybrid/SceneSectionStreamingSystem.cs:474)
    28. Unity.Entities.ComponentSystem:InternalUpdate() (at Library/PackageCache/com.unity.entities@0.2.0-preview.18/Unity.Entities/ComponentSystem.cs:843)
    29. Unity.Entities.ComponentSystemBase:Update() (at Library/PackageCache/com.unity.entities@0.2.0-preview.18/Unity.Entities/ComponentSystem.cs:307)
    30. Unity.Entities.ComponentSystemGroup:OnUpdate() (at Library/PackageCache/com.unity.entities@0.2.0-preview.18/Unity.Entities/ComponentSystemGroup.cs:101)
    31. Unity.Entities.ComponentSystem:InternalUpdate() (at Library/PackageCache/com.unity.entities@0.2.0-preview.18/Unity.Entities/ComponentSystem.cs:843)
    32. Unity.Entities.ComponentSystemBase:Update() (at Library/PackageCache/com.unity.entities@0.2.0-preview.18/Unity.Entities/ComponentSystem.cs:307)
    33. Unity.Entities.DummyDelegateWrapper:TriggerUpdate() (at Library/PackageCache/com.unity.entities@0.2.0-preview.18/Unity.Entities/ScriptBehaviourUpdateOrder.cs:152)
    34.  
    I hope this will help you in finding the issue!
     

    Attached Files:

    Last edited: Nov 26, 2019
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,685
    Which Unity version you’re using?
     
    Zec_ likes this.
  3. Zec_

    Zec_

    Joined:
    Feb 9, 2017
    Posts:
    148
    Oh, right. Apologies for forgetting that. 2019.3.0b12 and the Entities version is specifically 0.2.0 preview.18

    Edited that into my original post as well.
     
    eizenhorn likes this.
  4. Zec_

    Zec_

    Joined:
    Feb 9, 2017
    Posts:
    148
    Couldn't find info on how you want to handle bug reports for DOTS, so I assume you want us to use the bug report system. I therefore created a proper bug report there with case number 1021070. I'll add that info to the top post as well.
     
    Last edited: Nov 26, 2019
  5. EdRowlett-Barbu

    EdRowlett-Barbu

    Joined:
    Mar 16, 2015
    Posts:
    88
    I'm also affected by this issue, indeed I have references to prefabs inside my serialized subscenes, used for spawning prefabs by my spawning system implementation. Is there a workaround for this? What is the status on this issue?
    (Unity 2019.3.0f1 and Entities 0.3.0 preview 4)
     
  6. EdRowlett-Barbu

    EdRowlett-Barbu

    Joined:
    Mar 16, 2015
    Posts:
    88
    Figured it out after some work, you got to use the new scriptable build pipeline system. Once I created a build with that, it worked
     
    Zec_ likes this.
  7. Zec_

    Zec_

    Joined:
    Feb 9, 2017
    Posts:
    148
    Oh? That's interesting. So you've got it working in builds, but what about play-mode when working in the Editor? Have you been able load the SubScenes with prefab references there?
     
  8. EdRowlett-Barbu

    EdRowlett-Barbu

    Joined:
    Mar 16, 2015
    Posts:
    88
    Never had an issue inside the editor, in play mode. Note that I'm using Entities 0.3 though, not 0.2. Just in standalone builds I had issues with the subscene loading.
    Maybe make sure you have scriptable build pipeline installed still? Perhaps it still needs that in 0.2 in editor, don't know, worth a try. Also perhaps try the release version? No reason to stick with the beta now that 2019.3.0f1 is out I think