Search Unity

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

Resolved Entities 1.0.0-pre.44 ComponentSystemGroup sorting is completely broken

Discussion in 'Entity Component System' started by DreamingImLatios, Feb 17, 2023.

  1. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,984
    Update: While I did find the cause and workaround to the original error, I now get similar issues which have different causes that I am unable to decipher fully.

    I have reported a bug: 32561.
    In it, you will find a project that used to work correctly in pre 15. It includes an embedded version of my framework. You can diff that version's directories with the latest version on GitHub to see what I changed to bring about compatibility.

    This is pretty much a showstopper for me. :mad:

    Original post as follows:
    I get spammed with this stack trace:
    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. Unity.Collections.LowLevel.Unsafe.UnsafeList`1[T].get_Item (System.Int32 index) (at ./Library/PackageCache/com.unity.collections@2.1.0-pre.11/Unity.Collections/UnsafeList.cs:136)
    3. Unity.Entities.TypeManager.GetSystemAttributes (System.Int32 systemTypeIndex, Unity.Entities.TypeManager+SystemAttributeKind kind) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities/Types/TypeManagerSystems.cs:841)
    4. Unity.Entities.ComponentSystemGroup.ComputeSystemOrdering (System.Int32 sysType, System.Int32 ourTypeIndex) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities/ComponentSystemGroup.cs:525)
    5. Unity.Entities.ComponentSystemGroup.GenerateMasterUpdateList () (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities/ComponentSystemGroup.cs:402)
    6. Unity.Entities.ComponentSystemGroup.RecurseUpdate () (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities/ComponentSystemGroup.cs:371)
    7. Unity.Entities.ComponentSystemGroup.RecurseUpdate () (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities/ComponentSystemGroup.cs:380)
    8. Unity.Entities.ComponentSystemGroup.RecurseUpdate () (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities/ComponentSystemGroup.cs:380)
    9. Unity.Entities.ComponentSystemGroup.SortSystems () (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities/ComponentSystemGroup.cs:554)
    What do I need to do to ensure whatever isn't getting initialized gets initialized? Right now this new version is completely unusable for me because of these errors.

    Edit: Only happens when sorting systems instantiated generically during OnCreate(). I am disabling sorting for those groups and the issue disappears.
     
    Last edited: Feb 17, 2023
  2. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    Looks like your type manager failed to initialize to me as your shared statics don't seem setup.
    This is definitely your first error? Even before entering game?

    I had an issue with my typemanager breaking after upgrading from putting a InputActionReference on a managed IComponentData and a new check for nested native containers was (I believe) incorrectly doing it's check on managed components.

    Only way I could fix it was commenting out the check


    Not saying this is your issue, but I actually got an exception in TypeManager initialize which I would if it didn't initialize properly
    -edit-

    actually there appears to be a check beforehand
    Assertions.Assert.IsTrue(s_Initialized, "The TypeManager must be initialized before the TypeManager can be used.");
    so your typemanager must have been setup

    Code (CSharp):
    1.             //todo: check that it's in range
    2.             //if (IsSystemTypeIndex(systemTypeIndex))
    3.             {
    4.  
    5.                 var list = attributesList[systemTypeIndex];
    6.  
    7.                 for (int i = 0; i < list.Length; i++)
    8.                 {
    9.                     if (list[i].Kind == kind)
    10.                         ret.Add(list[i]);
    11.                 }
    12.             }
    i assume your system type index is out of range which means they weren't found by typemanager when initialized. Are you manually creating some generic systems at runtime?
     
    Last edited: Feb 17, 2023
  3. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,984
    No. The issue is that generic managed systems don't get registered with the TypeManager whatsoever. Workaround is to ensure all generic systems get added to a unique ComponentSytemGroup that contains no other systems, and then disable system sorting on that group.
     
  4. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    Are they generic systems your creating yourself at runtime?
     
  5. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,984
    Yes.

    This has always worked in previous releases. It stopped working this release because Unity now caches system attributes at TypeManager initialization. I have a workaround, but I'm willing to bet that anyone who tries to load in mods after startup is going to have a bad time. Unity really should lazy-initialize these caches.
     
  6. Laicasaane

    Laicasaane

    Joined:
    Apr 15, 2015
    Posts:
    289
    Could you please share me this workaround? Thanks!
     
  7. Laicasaane

    Laicasaane

    Joined:
    Apr 15, 2015
    Posts:
    289
    This is somewhat perplexing since generics is a very integral part of any codebase. But it seems to me generics is gradually discouraged by Unity Entities. There was already a lot of hassle to use generics in the previous version of Entities, and this new version has just made it unusable.
     
  8. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,984
    I don't even know what is going on anymore. But here is the latest issue. This is just from a DefaultWorldInitialization.GetAllSystems(WorldFilterFlags.Default):
    Code (CSharp):
    1. System.IndexOutOfRangeException: NewLength 11 is out of range of '10' Capacity.
    2.   at Unity.Collections.FixedList.CheckResize[BUFFER,T] (System.Int32 newLength) [0x00016] in .\Library\PackageCache\com.unity.collections@2.1.0-pre.11\Unity.Collections\FixedList.gen.cs:435
    3.   at Unity.Collections.FixedList128Bytes`1[T].set_Length (System.Int32 value) [0x00001] in .\Library\PackageCache\com.unity.collections@2.1.0-pre.11\Unity.Collections\FixedList.gen.cs:2742
    4.   at Unity.Collections.FixedList128Bytes`1[T].AddNoResize (T& item) [0x00001] in .\Library\PackageCache\com.unity.collections@2.1.0-pre.11\Unity.Collections\FixedList.gen.cs:2885
    5.   at Unity.Collections.FixedList128Bytes`1[T].Add (T& item) [0x00000] in .\Library\PackageCache\com.unity.collections@2.1.0-pre.11\Unity.Collections\FixedList.gen.cs:2861
    6.   at Unity.Entities.TypeManager.GetSystemAttributes (System.Int32 systemTypeIndex, Unity.Entities.TypeManager+SystemAttributeKind kind) [0x00057] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.44\Unity.Entities\Types\TypeManagerSystems.cs:842
    7.   at Unity.Entities.ComponentSystemSorter.FindConstraints$BurstManaged (System.Int32 parentTypeIndex, Unity.Collections.LowLevel.Unsafe.UnsafeList`1[Unity.Entities.ComponentSystemSorter+SystemElement]* sysElemsPtr, Unity.Collections.NativeHashMap`2[System.Int32,System.Int32]* lookupDictionary, Unity.Entities.TypeManager+SystemAttributeKind afterkind, Unity.Entities.TypeManager+SystemAttributeKind beforekind, Unity.Collections.LowLevel.Unsafe.UnsafeList`1[System.Int32]* badSystemTypeIndices) [0x0002d] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.44\Unity.Entities\ComponentSystemSorter.cs:380
    8.   at Unity.Entities.ComponentSystemSorter+FindConstraints_000001C7$BurstDirectCall.Invoke (System.Int32 parentTypeIndex, Unity.Collections.LowLevel.Unsafe.UnsafeList`1[Unity.Entities.ComponentSystemSorter+SystemElement]* sysElemsPtr, Unity.Collections.NativeHashMap`2[System.Int32,System.Int32]* lookupDictionary, Unity.Entities.TypeManager+SystemAttributeKind afterkind, Unity.Entities.TypeManager+SystemAttributeKind beforekind, Unity.Collections.LowLevel.Unsafe.UnsafeList`1[System.Int32]* badSystemTypeIndices) [0x0000f] in <0c8b562657c1458a9c7caece41b1563d>:0
    9.   at Unity.Entities.ComponentSystemSorter.FindConstraints (System.Int32 parentTypeIndex, Unity.Collections.LowLevel.Unsafe.UnsafeList`1[Unity.Entities.ComponentSystemSorter+SystemElement]* sysElemsPtr, Unity.Collections.NativeHashMap`2[System.Int32,System.Int32]* lookupDictionary, Unity.Entities.TypeManager+SystemAttributeKind afterkind, Unity.Entities.TypeManager+SystemAttributeKind beforekind, Unity.Collections.LowLevel.Unsafe.UnsafeList`1[System.Int32]* badSystemTypeIndices) [0x00008] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.44\Unity.Entities\ComponentSystemSorter.cs:372
    10.   at Unity.Entities.TypeManager.SortSystemTypes (System.Collections.Generic.List`1[T] systemTypes) [0x000d0] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.44\Unity.Entities\Types\TypeManagerSystems.cs:596
    11.   at Unity.Entities.TypeManager.GetSystems (Unity.Entities.WorldSystemFilterFlags filterFlags, Unity.Entities.WorldSystemFilterFlags requiredFlags) [0x000b1] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.44\Unity.Entities\Types\TypeManagerSystems.cs:511
    12.   at Unity.Entities.DefaultWorldInitialization.GetAllSystems (Unity.Entities.WorldSystemFilterFlags filterFlags, System.Boolean requireExecuteInEditor) [0x00014] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.44\Unity.Entities\DefaultWorldInitialization.cs:357
    13.   at LatiosBootstrap.Initialize (System.String defaultWorldName) [0x00021] in B:\Unity Projects\Latios Framework Stuff\Kinemation Bug Fixing06\Assets\_Code\LatiosBootstrap.cs:44
    14.   at Unity.Entities.DefaultWorldInitialization.Initialize (System.String defaultWorldName, System.Boolean editorWorld) [0x00038] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.44\Unity.Entities\DefaultWorldInitialization.cs:140
    15.   at Unity.Entities.AutomaticWorldBootstrap.Initialize () [0x00001] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.44\Unity.Entities.Hybrid\Injection\AutomaticWorldBootstrap.cs:16
    Somehow in TypeManagerSystems, at systemTypeIndex 171, I have an unintialized "list" with millions of items, capacity of 101, and IsCreated = true. (Pretty sure that's just uninitialized memory or a bad index to begin with.)

    Prior to this, I having an issue getting closed subscenes to load. They just quietly remained unloaded. Open subscenes were live baking fine.
     
    bb8_1 likes this.
  9. Laicasaane

    Laicasaane

    Joined:
    Apr 15, 2015
    Posts:
    289
    @DreamingImLatios I get these issues as well. After 7 hours trying to understand what's gone wrong, I've now reverted to the previous version.
     
    bb8_1 likes this.
  10. toomasio

    toomasio

    Joined:
    Nov 19, 2013
    Posts:
    195
    Getting very similar errors. I am not as big brained as you guys....only have very vanilla stuff going on in my project. I also can not open any of the entity editors without Unity Crashing. I thought it was a UI Elements issue. Made sure I didnt have duplicates in my package manifest, removed all entities packages, deleted library folder, re installed everything I needed. Same errors.

    Errors:
    Error 1:
    Code (CSharp):
    1. ArgumentException: An item with the same key has already been added. Key: UnityEngine.UIElements.StyleSheet+ImportStruct[]
    2. System.Collections.Generic.Dictionary`2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) (at <83161767e3f34f4a9c1453ea3e22d1f1>:0)
    3. System.Collections.Generic.Dictionary`2[TKey,TValue].Add (TKey key, TValue value) (at <83161767e3f34f4a9c1453ea3e22d1f1>:0)
    4. Unity.Entities.TypeManager.ThrowOnNestedNativeContainerComponentData (System.Type type, System.Type baseType, System.Collections.Generic.Dictionary`2[TKey,TValue] nestedContainerCache) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities/Types/TypeManager.cs:2798)
    5. Unity.Entities.TypeManager.ThrowOnNestedNativeContainerComponentData (System.Type type, System.Type baseType, System.Collections.Generic.Dictionary`2[TKey,TValue] nestedContainerCache) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities/Types/TypeManager.cs:2819)
    6. Unity.Entities.TypeManager.ThrowOnNestedNativeContainerComponentData (System.Type type, System.Type baseType, System.Collections.Generic.Dictionary`2[TKey,TValue] nestedContainerCache) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities/Types/TypeManager.cs:2819)
    7. Unity.Entities.TypeManager.ThrowOnNestedNativeContainerComponentData (System.Type type, System.Type baseType, System.Collections.Generic.Dictionary`2[TKey,TValue] nestedContainerCache) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities/Types/TypeManager.cs:2819)
    8. Unity.Entities.TypeManager.ThrowOnNestedNativeContainerComponentData (System.Type type, System.Type baseType, System.Collections.Generic.Dictionary`2[TKey,TValue] nestedContainerCache) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities/Types/TypeManager.cs:2819)
    9. Unity.Entities.TypeManager.CheckIsAllowedAsManagedComponentData (System.Type type, System.String baseTypeDesc, System.Collections.Generic.Dictionary`2[TKey,TValue] nestedContainerCache, System.Boolean& hasNativeContainer) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities/Types/TypeManager.cs:2734)
    10. Unity.Entities.TypeManager.BuildComponentType (System.Type type, Unity.Entities.TypeIndex[] writeGroups, System.Collections.Generic.Dictionary`2[TKey,TValue] hashCache, System.Collections.Generic.Dictionary`2[TKey,TValue] nestedContainerCache) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities/Types/TypeManager.cs:2896)
    11. Unity.Entities.TypeManager.BuildComponentType (System.Type type, System.Collections.Generic.Dictionary`2[TKey,TValue] hashCache, System.Collections.Generic.Dictionary`2[TKey,TValue] nestedContainerCache) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities/Types/TypeManager.cs:2836)
    12. Unity.Entities.TypeManager.AddAllComponentTypes (System.Type[] componentTypes, System.Int32 startTypeIndex, System.Collections.Generic.Dictionary`2[TKey,TValue] writeGroupByType, System.Collections.Generic.Dictionary`2[TKey,TValue] descendantCountByType) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities/Types/TypeManager.cs:2610)
    13. UnityEngine.Debug:LogException(Exception)
    14. Unity.Debug:LogException(Exception) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities/Stubs/Unity/Debug.cs:19)
    15. Unity.Entities.TypeManager:AddAllComponentTypes(Type[], Int32, Dictionary`2, Dictionary`2) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities/Types/TypeManager.cs:2633)
    16. Unity.Entities.TypeManager:InitializeAllComponentTypes() (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities/Types/TypeManager.cs:2504)
    17. Unity.Entities.TypeManager:Initialize() (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities/Types/TypeManager.cs:1455)
    18. Unity.Entities.BindingRegistry:Initialize() (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities.Hybrid/Bindings/BindingRegistry.cs:83)
    19. Unity.Entities.BindingRegistry:.cctor() (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities.Hybrid/Bindings/BindingRegistry.cs:76)
    20. UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes(Type[])
    21.  
    Error 2:
    Code (CSharp):
    1. System.ArgumentException: TypeManager initialization failed. Please fix all exceptions logged above before continuing.
    2.   at Unity.Entities.TypeManager.InitializeAllComponentTypes () [0x00230] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.44\Unity.Entities\Types\TypeManager.cs:2512
    3.   at Unity.Entities.TypeManager.Initialize () [0x001b5] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.44\Unity.Entities\Types\TypeManager.cs:1455
    4.   at Unity.Entities.BindingRegistry.Initialize () [0x00000] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.44\Unity.Entities.Hybrid\Bindings\BindingRegistry.cs:83
    5.   at Unity.Entities.BindingRegistry..cctor () [0x00028] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.44\Unity.Entities.Hybrid\Bindings\BindingRegistry.cs:76
    6. UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes (System.Type[])
    Error 3:
    Code (CSharp):
    1. System.NullReferenceException: Object reference not set to an instance of an object
    2.   at Unity.Scenes.Editor.TypeDependencyCache.RegisterComponentTypes () [0x0002f] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.44\Unity.Scenes.Editor\TypeDependencyCache.cs:87
    3.   at Unity.Scenes.Editor.TypeDependencyCache..cctor () [0x00061] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.44\Unity.Scenes.Editor\TypeDependencyCache.cs:61
    4. UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes (System.Type[])
    Error 4:
    Code (CSharp):
    1. System.TypeInitializationException: The type initializer for 'Unity.Entities.BindingRegistry' threw an exception. ---> System.ArgumentException: TypeManager initialization failed. Please fix all exceptions logged above before continuing.
    2.   at Unity.Entities.TypeManager.InitializeAllComponentTypes () [0x00230] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.44\Unity.Entities\Types\TypeManager.cs:2512
    3.   at Unity.Entities.TypeManager.Initialize () [0x001b5] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.44\Unity.Entities\Types\TypeManager.cs:1455
    4.   at Unity.Entities.BindingRegistry.Initialize () [0x00000] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.44\Unity.Entities.Hybrid\Bindings\BindingRegistry.cs:83
    5.   at Unity.Entities.BindingRegistry..cctor () [0x00028] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.44\Unity.Entities.Hybrid\Bindings\BindingRegistry.cs:76
    6.    --- End of inner exception stack trace ---
    7.   at Unity.Entities.Editor.BindingRegistryLiveProperties.RegisterBindingsFromBuiltinTypes () [0x00000] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.44\Unity.Entities.Editor\LiveProperties\BindingRegistryLiveProperties.cs:312
    8.   at Unity.Entities.Editor.BindingRegistryLiveProperties..cctor () [0x00010] in .\Library\PackageCache\com.unity.entities@1.0.0-pre.44\Unity.Entities.Editor\LiveProperties\BindingRegistryLiveProperties.cs:22
    9. UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes (System.Type[])
    Editor Crash Log:
    Code (CSharp):
    1. Obtained 27 stack frames
    2. 0x000001adac2a8f68 (Mono JIT Code) (wrapper managed-to-native) System.Buffer:InternalMemcpy (byte*,byte*,int)
    3. 0x000001adadd649e3 (Mono JIT Code) System.Buffer:Memcpy (byte*,byte*,int)
    4. 0x000001adac2a8ed3 (Mono JIT Code) string:memcpy (byte*,byte*,int)
    5. 0x000001aebcd6e893 (Mono JIT Code) Unity.Entities.Editor.ComponentDataDiffer:CanWatch (Unity.Entities.ComponentType) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities.Editor/Hierarchy/Model/ChangeTracking/ComponentDataDiffer.cs:308)
    6. 0x000001aebcd6df7b (Mono JIT Code) Unity.Entities.Editor.ComponentDataDiffer:.ctor (Unity.Entities.ComponentType) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities.Editor/Hierarchy/Model/ChangeTracking/ComponentDataDiffer.cs:318)
    7. 0x000001aebcd68593 (Mono JIT Code) Unity.Entities.Editor.HierarchyEntityChangeTracker:.ctor (Unity.Entities.World,Unity.Collections.Allocator) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities.Editor/Hierarchy/Model/ChangeTracking/HierarchyEntityChangeTracker.cs:212)
    8. 0x000001aebcd6742b (Mono JIT Code) Unity.Entities.Editor.HierarchyUpdater:SetWorld (Unity.Entities.World) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities.Editor/Hierarchy/Model/HierarchyUpdater.cs:190)
    9. 0x000001aebcc2626b (Mono JIT Code) Unity.Entities.Editor.Hierarchy:SetWorld (Unity.Entities.World) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities.Editor/Hierarchy/Model/Hierarchy.cs:437)
    10. 0x000001aebcd66fc3 (Mono JIT Code) Unity.Entities.Editor.HierarchyWindow:OnWorldSelected (Unity.Entities.World) (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities.Editor/Hierarchy/HierarchyWindow.cs:302)
    11. 0x000001aebccb7808 (Mono JIT Code) Unity.Entities.Editor.DOTSEditorWindow:Update () (at ./Library/PackageCache/com.unity.entities@1.0.0-pre.44/Unity.Entities.Editor/Common/DOTSEditorWindow.cs:196)
    12. 0x000001aeed783109 (Mono JIT Code) UnityEditor.HostView:SendUpdate ()
    13. 0x000001aeed6c70d0 (Mono JIT Code) UnityEditor.EditorApplication:Internal_CallUpdateFunctions ()
    14. 0x000001adaf051305 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void (object,intptr,intptr,intptr)
    15. 0x00007ffb950f0394 (mono-2.0-bdwgc) mono_jit_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/mini/mini-runtime.c:3445)
    16. 0x00007ffb9502eb44 (mono-2.0-bdwgc) do_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3066)
    17. 0x00007ffb9502ecdc (mono-2.0-bdwgc) mono_runtime_invoke (at C:/build/output/Unity-Technologies/mono/mono/metadata/object.c:3113)
    18. 0x00007ff6fb6aa4f4 (Unity) scripting_method_invoke
    19. 0x00007ff6fb68ae64 (Unity) ScriptingInvocation::Invoke
    20. 0x00007ff6fb685ab5 (Unity) ScriptingInvocation::Invoke<void>
    21. 0x00007ff6fb7c1c4b (Unity) Scripting::UnityEditor::EditorApplicationProxy::Internal_CallUpdateFunctions
    22. 0x00007ff6fc1abea5 (Unity) SceneTracker::Update
    23. 0x00007ff6fc2cae99 (Unity) Application::TickTimer
    24. 0x00007ff6fc75652a (Unity) MainMessageLoop
    25. 0x00007ff6fc75b2d0 (Unity) WinMain
    26. 0x00007ff6fdb2652e (Unity) __scrt_common_main_seh
    27. 0x00007ffbfec77614 (KERNEL32) BaseThreadInitThunk
    28. 0x00007ffc005226a1 (ntdll) RtlUserThreadStart
     
    Last edited: Feb 17, 2023
  11. filod

    filod

    Joined:
    Oct 3, 2015
    Posts:
    191
    same error...
     
  12. desertGhost_

    desertGhost_

    Joined:
    Apr 12, 2018
    Posts:
    258
    I also had this issue with having an AsyncOperationHandle<GameObject> in a managed IComponentData. In my case I could remove the IComponent data and store the data in a dictionary on the system...
     
  13. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    This is the error I have. Only fix I have for you is either remove your data from managed components or edit the package above and remove the check.

    https://github.com/tertle/com.unity.entities

    I applied the fix to a fork here so you can just add this to your project via package manager if you don't want to do it yourself
     
    filod and toomasio like this.
  14. Kleptine

    Kleptine

    Joined:
    Dec 23, 2013
    Posts:
    254
    I noticed the line in the change log:
    "ComponentSystemGroup.SortSystems() taking many milliseconds for large number of systems."
     
  15. Laicasaane

    Laicasaane

    Joined:
    Apr 15, 2015
    Posts:
    289
    It's in the "Fixed" section, so that means it was a bug and now SortSystems shouldn't take many milliseconds anymore. But their fix has eventually broken other things people are depending on.
     
  16. elliotc-unity

    elliotc-unity

    Unity Technologies

    Joined:
    Nov 5, 2015
    Posts:
    228
    Hi! I’m the sortsystems guy.

    SortSystems took 75ms to sort 1000 systems, which we all said was too much. So, as you noticed, I registered all the systems up front, and then bursted the sort. That made it take about 7-8ms to sort 1000 systems.

    Then, I started sorting otherwise unconstrained systems by comparing their stable type hashes, where before we were comparing their names. This made it take 1-2ms. So I was happy about that and called it good.

    Generally, creating systems at runtime without the use of ICustomBootstrap was already a recipe for badness before this change, because it makes it impossible to respect CreateAfter and CreateBefore attributes. It’s an even worse recipe for badness to create other systems _inside_ somebody _else_’s OnCreate method, because then their OnCreate happens in the middle of yours, and nobody can make any valid assumptions. I haven’t yet seen a use case where it was really necessary, but I’m open to being convinced.

    Now, it seems there are two bugs here:

    - There’s the original bug, where a generic system whose concrete type was never seen in the typemanager is created and attempts to sort; it makes sense to me that this breaks, and I probably know how to fix it. This would probably also break in more civilized ICustomBootstrap use cases as well, so I agree with the bug report.

    - There’s the managed IComponentData complaining about nested native containers, which my friend Scott is going to fix next week. It’s just an overzealous check that forgot that it shouldn’t apply to class components.

    Also, chill, we don’t hate generics. We just love speed, and speed means bursting stuff, and bursting stuff means a lot of pre-registration to avoid reflection after startup, and sometimes generics make that tricky.
     
    Greexonn, xVergilx, toomasio and 3 others like this.
  17. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,029
    Awesome. Btw is there any plan to make ComponentSystemGroup burst compatible in future to make system update much more faster?
     
  18. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,984
    This is the bug I first encountered, but it is NOT the bug I reported. The bug I reported is calling GetAllSystems() at the beginning of an ICustomBootstrap. By definition, that cannot have any generic systems, and I have only created three systems at that time (the three top-level systems because I do my own custom creation and adding of systems after the call that is throwing). So something else is wrong!

    I have 5 use cases, some of which I have been complaining about for the last three years. I would love to have better solutions to these use cases. If you want to talk about it, PM me. We can talk in chat or organize a voice or video call. But I am tired of talking about these publicly on the forums.
    These shouldn't even exist. They don't work for the majority of use cases where they would be helpful because they require the systems to be in the same parent ComponentSystemGroup. A secondary OnCreate()-like callback (splitting the whole OnCreate() process into two stages) would solve many of their use cases much more elegantly, and be much safer in general.
     
  19. elliotc-unity

    elliotc-unity

    Unity Technologies

    Joined:
    Nov 5, 2015
    Posts:
    228
    Groups have no bearing on creation order, actually. I wish they did, and everybody thinks they do (even internally), but they don’t.

    Will investigate the rest of the stuff mentioned here.
     
  20. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,984
    If you have a [CreateBefore(typeof(SystemThatBelongsInADifferentGroup))], you get a warning. That's been that way since those attributes existed, and still is in 44, as I learned while trying to work around these other bugs.
     
    toomasio and TheOtherMonarch like this.
  21. TheOtherMonarch

    TheOtherMonarch

    Joined:
    Jul 28, 2012
    Posts:
    791
    I just wanted to say that with multiple worlds adding systems to other worlds during OnCreate() is common. I guess it would not effect this ordering.
     
  22. Laicasaane

    Laicasaane

    Joined:
    Apr 15, 2015
    Posts:
    289
    For me, the use of [CreateAfter], [CreateBefore], and [UpdateInGroup] makes it hard to understand a part of the ECS world that matters at first glance. That means I only interest in the systems developed by my team. But those attributes hide the this structure of the world. So I use ICustomBootstrap to explicitly specify which systems are being used and where they are placed along the PlayerLoop, for the ease of understanding and navigating the codebase.

    I'm using Latios Framework because it gives me a way to declare this specification clearly. So many thanks if you have a better suggestion for my case?
     
    Last edited: Feb 20, 2023
  23. elliotc-unity

    elliotc-unity

    Unity Technologies

    Joined:
    Nov 5, 2015
    Posts:
    228
    Slowly working through this thread, replies to a bunch of separate things below.

    ---------------------------------------------
    I downloaded @DreamingImLatios bug report project, and while I could not reproduce any sorting issues running it myself, I looked at the log and realized that the first error is actually about a system having ELEVEN (!) create before/after attributes affecting it, which I assumed would never happen, and it makes sense that sorting would explode in that case. I'll up it to 40, and improve the error message as well.

    That doesn't seem related to the non-rendering when the subscene is closed, though.

    There are some other errors and warnings happening as well, but nothing that seems obviously relevant to this thread.
    ----------------------------------------------
    That's certainly true of UpdateBefore, but I can't reproduce that happening with CreateBefore here.
    ----------------------------------------------
    Explicit instantiation of a giant list of systems via ICustomBootstrap already works, and you can see the netcode package doing that in com.unity.netcode/Runtime/ClientServerWorld/ClientServerBootstrap.cs. Note that GetAllSystems does the sorting by CreateAfter/Before for you, and the idea is that the world system filter flags will give you the set of systems you actually want.

    This is admittedly not, like, the most luxurious experience, and I can definitely imagine that it doesn't cover all reasonable usages.

    What would you guys say about the following idea for a set of additions that might address this better:
    - Expose a version of GetAllSystems that doesn't sort for you.
    - Separately, expose a sort-systems-by-CreateAfter/CreateBefore. Maybe these would be Type's, or maybe they would be lists of system type indices, for improved internal burstability and therefore speed.
    - When you create systems in an order that violates their constraints, warn about it (this one might be tricky to do sufficiently cheaply, we'll see).
    - Show in a window somewhere what order systems were created in.

    Then you could make up your list of system types or system type indices that was either your own explicit list or was a modified version of what GetAllSystems gave you, but you could still guarantee that it would satisfy the order that all the system authors thought it should by calling SortSystemsForCreation. However, you'd still be responsible for instantiating all the Unity-provided systems, of which there are a whole bunch. (Looks like Latios framework does this part already.)

    Good/bad/mediocre idea?
     
  24. elliotc-unity

    elliotc-unity

    Unity Technologies

    Joined:
    Nov 5, 2015
    Posts:
    228
    We generally intend to do this at Some Point (tm), but we've still been finding bigger fish to fry in our profiles, so we haven't started looking at it yet.
     
    optimise likes this.
  25. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,984
    I know exactly what error you are talking about, and if you stepped into it with a debugger, you might find the list of attributes contains millions of attributes and greatly outnumbers the capacity of the list. It is uninitialized memory. No system in that project has that many attributes.

    If you want to see the runtime sorting issues, go to ManagedStructStorageCleanupSystems.cs line 73 where I set EnableSystemSorting = false. Comment out that line, and you will get the sorting errors. The workaround of disabling sorting is sufficient for my use case (though finding that workaround was a total shot in the dark), but doesn't work in a project that dynamically loads an assembly containing systems after the TypeManager has already been initialized.

    This was definitely the case in15, though I may have been mistaken about it still being the case in 44. My main use case is trying to add a system to multiple system groups inside of OnCreate(). This only works if the ComponentSystemGroup has its OnCreate() called first because otherwise it doesn't have the list data allocated. I wish that list data was lazy-initialized, because then I wouldn't have any sort of create-order dependencies between systems. I still think a two-stage OnCreate process would be a better solution. First stage to initialize internal state, and the second stage to do inter-system dependency registration stuff.

    These sound like good improvements regardless of all the other issues.

    Make this suppressible (extra argument in the creation call method).
     
    Occuros likes this.
  26. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,029
    I would like to require further SystemBase managed system performance optimization since it's still very slow and it's critical for the code that can't support burst like UI logic.
     
  27. elliotc-unity

    elliotc-unity

    Unity Technologies

    Joined:
    Nov 5, 2015
    Posts:
    228
    Why would you want to intentionally violate constraints specified by the system author?
     
  28. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,984
    The author's project is not the same as mine.

    Often times these constraints aren't actually constraints between systems, but constraints between resources. If SystemA depends on a resource and has an CreateAfter(typeof(SystemB)), but in my project, I remove SystemB and create the resource via SystemC instead, and SystemA acquires the resource without a hard reference to SystemB (using entities instead), then I want to violate that CreateAfter constraint because it is nonsensical to my project.

    I didn't ask to make the warning suppressible because I want to do it all the time. I asked for it because sometimes stupid happens.

    Remember, my project is completely broken right now, with no error message that actually explains the problem to me, and none of the code I changed when updating from a previously working version with zero errors was related in any way to these issues (later I made changes to work around regressions as I made some lucky guesses with cryptic errors, but that's beside my point). My point is, stupid happens.
     
    Laicasaane, JesOb and elliotc-unity like this.
  29. elliotc-unity

    elliotc-unity

    Unity Technologies

    Joined:
    Nov 5, 2015
    Posts:
    228
    That makes perfect sense, thanks.
     
  30. Laicasaane

    Laicasaane

    Joined:
    Apr 15, 2015
    Posts:
    289
    Right. Sometimes I have to modify the source code just to disable some behaviours determined by the author and to be able to inject something of my own. Sometimes I have to remove some systems entirely and just use mine. Because our philosophy POVs are different, or the prodecure defined by the author doesn't match with the architecture of my codebase.
     
    elliotc-unity likes this.
  31. Selmar

    Selmar

    Joined:
    Sep 13, 2011
    Posts:
    55
    I have another "use case". I have a separate simulation world that uses Physics, and I want this world to update in its entirety *before* the regular fixed update. I also want to be able to use the entities systems view, to be able to visually confirm update order between systems and such (which is why I have this somewhat questionable solution).
    Since I use physics, I have to move the entire FixedStepSimulationSystemGroup from the regular simulation system group to a nested group that updates before the fixed step.

    This works fine, but generates similar warnings.
     
  32. DreamingImLatios

    DreamingImLatios

    Joined:
    Jun 3, 2017
    Posts:
    3,984
    While the subscene loading issue is still present in the latest pre.47 hotfix, the system sorting issues, including creation sorting in the ICustomBootstrap, have been resolved!

    Thanks everyone!

    I am uploading a new bug report for the silently failing subscenes, and will post a new thread once that is ready. That's currently the only blocking issue I have now. The other issues with the release I haven't mentioned seemed to be resolved with the system sorting issues.
     
  33. linfuqing

    linfuqing

    Joined:
    May 11, 2015
    Posts:
    166
    Hey,it's something wrong in my case:
    Code (CSharp):
    1. public abstract class SystemGroupBase : ComponentSystemGroup
    2. {
    3. }
    4.  
    5. [UpdateInGroup(typeof(SystemGroupBase), OrderFirst = true)]
    6. public partial class MySystem : SystemBase
    7. {
    8. }
    9.  
    10. public partial class MySystemGroup : SystemGroupBase
    11. {
    12. }
    13.  
    Edit:

    This is what's wrong in ComponentSystemGroup.ComputeSystemOrdering:
    Code (CSharp):
    1.         internal static int ComputeSystemOrdering(int sysType, int ourTypeIndex)
    2.         {
    3.             if (ourTypeIndex == -1 || sysType == -1)
    4.                 return 1;
    5.  
    6.             var attrs = TypeManager.GetSystemAttributes(sysType, TypeManager.SystemAttributeKind.UpdateInGroup);
    7.             for (int i=0; i<attrs.Length; i++)
    8.             {
    9.                 var attr = attrs[i];
    10.  
    11.                 //attr.TargetSystemTypeIndex == -1
    12.                 if (attr.TargetSystemTypeIndex == ourTypeIndex)
    13.                 {
    14.                     if ((attr.Flags & TypeManager.SystemAttribute.kOrderFirstFlag) != 0)
    15.                     {
    16.                         return 0;
    17.                     }
    18.  
    19.                     if ((attr.Flags & TypeManager.SystemAttribute.kOrderLastFlag) != 0)
    20.                     {
    21.                         return 2;
    22.                     }
    23.                 }
    24.             }
    25.  
    26.             return 1;
    27.         }
    28.