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

Bug World.GetOrCreateSystemsAndLogException() Cause "NullReferenceException"

Discussion in 'Entity Component System' started by QuebecDev, Jun 30, 2023.

  1. QuebecDev

    QuebecDev

    Joined:
    May 9, 2020
    Posts:
    37
    Hi,

    I am having a "NullReferenceException" after calling "World:GetOrCreateSystemsAndLogException()" in a standalone build.

    I use TypeManager.GetSystems(WorldSystemFilterFlags.Streaming) to get 6 systems.

    Does anyone know how to fix this?

    ///
    /// Logs
    ///
    Create world: Streaming | 6 systems
    NullReferenceException: Object reference not set to an instance of an object
    at Unity.Collections.LowLevel.Unsafe.UnsafeParallelHashMapBase`2[TKey,TValue].TryGetFirstValueAtomic (Unity.Collections.LowLevel.Unsafe.UnsafeParallelHashMapData* data, TKey key, TValue& item, Unity.Collections.NativeParallelMultiHashMapIterator`1[TKey]& it) [0x00008] in .\Library\PackageCache\com.unity.collections@2.1.4\Unity.Collections\UnsafeParallelHashMap.cs:895
    at Unity.Collections.LowLevel.Unsafe.UnsafeParallelHashMap`2[TKey,TValue].TryGetValue (TKey key, TValue& item) [0x00001] in .\Library\PackageCache\com.unity.collections@2.1.4\Unity.Collections\UnsafeParallelHashMap.cs:1239
    at Unity.Entities.UnmanagedSystemTypeRegistryData.FindSystemMetaIndex (System.Int64 typeHash, System.Int32& index) [0x00001] in .\Library\PackageCache\com.unity.entities@1.0.11\Unity.Entities\SystemBaseRegistry.cs:102
    at Unity.Entities.SystemBaseRegistry.GetSystemTypeMetaIndex (System.Int64 typeHash) [0x0000c] in .\Library\PackageCache\com.unity.entities@1.0.11\Unity.Entities\SystemBaseRegistry.cs:149
    at Unity.Entities.WorldUnmanagedImpl.CreateUnmanagedSystemInternal (Unity.Entities.World self, System.Int32 structSize, System.Int64 typeHash, System.Int32 typeIndex, System.Void*& systemPtr, System.Boolean callOnCreate) [0x00001] in .\Library\PackageCache\com.unity.entities@1.0.11\Unity.Entities\WorldUnmanaged.cs:467
    at Unity.Entities.WorldUnmanagedImpl.CreateUnmanagedSystem (Unity.Entities.SystemTypeIndex t, System.Int64 typeHash, System.Boolean callOnCreate) [0x00001] in .\Library\PackageCache\com.unity.entities@1.0.11\Unity.Entities\WorldUnmanaged.cs:596
    at Unity.Entities.WorldUnmanagedImpl.CreateUnmanagedSystem (Unity.Entities.SystemTypeIndex t, System.Boolean callOnCreate) [0x00008] in .\Library\PackageCache\com.unity.entities@1.0.11\Unity.Entities\WorldUnmanaged.cs:677
    at Unity.Entities.WorldUnmanaged.CreateUnmanagedSystem (Unity.Entities.SystemTypeIndex unmanagedType, System.Boolean callOnCreate) [0x00000] in .\Library\PackageCache\com.unity.entities@1.0.11\Unity.Entities\WorldUnmanaged.cs:1109
    at Unity.Entities.World.GetOrCreateSystemsAndLogException (Unity.Collections.NativeList`1[T] types, System.Int32 typesCount, Unity.Collections.AllocatorManager+AllocatorHandle allocator) [0x00078] in .\Library\PackageCache\com.unity.entities@1.0.11\Unity.Entities\World.cs:1256
    UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object)
    UnityEngine.DebugLogHandler:LogException(Exception, Object)
    UnityEngine.Logger:LogException(Exception, Object)
    UnityEngine.Debug:LogException(Exception)
    Unity.Debug:LogException(Exception) (at .\Library\PackageCache\com.unity.entities@1.0.11\Unity.Entities\Stubs\Unity\Debug.cs:19)
    Unity.Entities.World:GetOrCreateSystemsAndLogException(NativeList`1, Int32, AllocatorHandle) (at .\Library\PackageCache\com.unity.entities@1.0.11\Unity.Entities\World.cs:1288)
    Unity.Entities.World:GetOrCreateSystemsAndLogException(NativeList`1, AllocatorHandle) (at .\Library\PackageCache\com.unity.entities@1.0.11\Unity.Entities\World.cs:1348)
    Sklapps.Engine.WorldCreator.WorldManager:AddSystem(World, IEnumerable`1, ComponentSystemGroup, DefaultRootGroups) (at .\Packages\com.sklapps\Engine.WorldCreator\Statics\WorldManager.cs:255)
    Sklapps.Engine.WorldCreator.WorldManager:AddSystem(World, WorldTickSetting, IEnumerable`1) (at .\Packages\com.sklapps\Engine.WorldCreator\Statics\WorldManager.cs:220)
    Sklapps.Engine.WorldCreator.WorldManager:CreateWorld(String, Boolean, WorldTickSetting, WorldFlags, WorldSystemFilterFlags) (at .\Packages\com.sklapps\Engine.WorldCreator\Statics\WorldManager.cs:156)
    Sklapps.Engine.WorldCreator.WorldManager:InitializeScene() (at .\Packages\com.sklapps\Engine.WorldCreator\Statics\WorldManager.cs:37)
     
  2. QuebecDev

    QuebecDev

    Joined:
    May 9, 2020
    Posts:
    37
    Anyone?
     
  3. tertle

    tertle

    Joined:
    Jan 25, 2011
    Posts:
    3,626
    When are you calling it?
     
  4. QuebecDev

    QuebecDev

    Joined:
    May 9, 2020
    Posts:
    37
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
     
  5. QuebecDev

    QuebecDev

    Joined:
    May 9, 2020
    Posts:
    37
    Yep that was the problem, Thank you... i was calling it to soon!

    This is better,

    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]