Hello there,
I am not sure if this is a place to write this, but I had these weird issues when I tried using DOTS. I was following the CodeMonkeys tutorial video about the DOTS “EXTREME PERFORMANCE with Unity DOTS! (ECS, Job System, Burst, Hybrid Game Objects)” and not soon after starting to create a few things I started getting issues.
To be honest, I have no idea what is relevant, so I am just adding all the details. So I use:
Unity version: 2022.3.10f1
Entities: 1.0.16
Entities Graphics: 1.0.16
URP: 14.0.8
Code Editor: Rider 2023.2.1
Also, as shown in the video I have enabled in ‘Project Settings>Editor’ the ‘Enter Play Mode Options’ checkbox and left ‘Reload Domain’ and ‘Reload Scene’ as unchecked. I am not sure if this is necessary or not or if this has anything to do with the issues I am having.
These are all the scripts I have made:
using Unity.Burst;
using Unity.Entities;
using Unity.Transforms;
public partial struct RotateSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<RotateSpeedComponent>();
}
public void OnUpdate(ref SystemState state)
{
var job = new RotateJob()
{
deltaTime = SystemAPI.Time.DeltaTime
};
job.ScheduleParallel();
}
[BurstCompile]
public partial struct RotateJob : IJobEntity
{
public float deltaTime;
public void Execute(ref LocalTransform transform, in RotateSpeedComponent speed)
{
transform = transform.RotateY(speed.value * deltaTime);
}
}
}
using Unity.Entities;
using UnityEngine;
public struct RotateSpeedComponent : IComponentData
{
public float value;
}
public class RotateSpeedAuthoring : MonoBehaviour
{
public float value;
private class Baker : Baker<RotateSpeedAuthoring>
{
public override void Bake(RotateSpeedAuthoring authoring)
{
AddComponent(GetEntity(TransformUsageFlags.Dynamic), new RotateSpeedComponent
{
value = authoring.value
});
}
}
}
I have created a cube added the authoring component, created a prefab, and duplicated the cube prefab multiple times in the scene and that’s it.
I want to use DOTS as it would benefit me greatly, however, these random leaks and errors happening already when I have nothing pretty much make me nervous…
Why am I getting all this? Am I missing something?
Everything works and I get no issues when entering and exiting the play mode, however, when I edit any script and the editor compiles the changes I get this error:
NullReferenceException: Object reference not set to an instance of an object
Unity.Entities.Editor.HierarchyWindow.OnCleanup () (at ./Library/PackageCache/com.unity.entities@1.0.16/Unity.Entities.Editor/Hierarchy/HierarchyWindow.cs:113)
Unity.Entities.Editor.DOTSEditorWindow.OnDisable () (at ./Library/PackageCache/com.unity.entities@1.0.16/Unity.Entities.Editor/Common/DOTSEditorWindow.cs:201)
And I get random Persistent allocations memory leaks:
Leak Detected : Persistent allocates 309 individual allocations.
Found 105 leak(s) from callstack:
0x000001394105a383 (Mono JIT Code) Unity.Collections.Memory/Unmanaged/Array:Resize (void*,long,long,Unity.Collections.AllocatorManager/AllocatorHandle,long,int) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/Memory.cs:79)
0x000001394105a243 (Mono JIT Code) Unity.Collections.Memory/Unmanaged:Allocate (long,int,Unity.Collections.AllocatorManager/AllocatorHandle) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/Memory.cs:20)
0x000001394105a03b (Mono JIT Code) Unity.Collections.AllocatorManager:TryLegacy (Unity.Collections.AllocatorManager/Block&) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/AllocatorManager.cs:1023)
0x0000013941059e2b (Mono JIT Code) Unity.Collections.AllocatorManager:Try (Unity.Collections.AllocatorManager/Block&) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/AllocatorManager.cs:1055)
0x0000013941059d9b (Mono JIT Code) Unity.Collections.AllocatorManager/AllocatorHandle:Try (Unity.Collections.AllocatorManager/Block&) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/AllocatorManager.cs:540)
0x0000013941059af3 (Mono JIT Code) Unity.Collections.AllocatorManager:AllocateBlock<Unity.Collections.AllocatorManager/AllocatorHandle> (Unity.Collections.AllocatorManager/AllocatorHandle&,int,int,int) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/AllocatorManager.cs:32)
0x00000139410599bb (Mono JIT Code) Unity.Collections.AllocatorManager:Allocate<Unity.Collections.AllocatorManager/AllocatorHandle> (Unity.Collections.AllocatorManager/AllocatorHandle&,int,int,int) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/AllocatorManager.cs:53)
0x0000013a1ac60173 (Mono JIT Code) Unity.Collections.LowLevel.Unsafe.UnsafeList`1<Unity.Entities.BakerEntityUsage/ReferencedEntityUsage>:ResizeExact<Unity.Collections.AllocatorManager/AllocatorHandle> (Unity.Collections.AllocatorManager/AllocatorHandle&,int) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/UnsafeList.cs:354)
0x0000013a1ac60093 (Mono JIT Code) Unity.Collections.LowLevel.Unsafe.UnsafeList`1<Unity.Entities.BakerEntityUsage/ReferencedEntityUsage>:SetCapacity<Unity.Collections.AllocatorManager/AllocatorHandle> (Unity.Collections.AllocatorManager/AllocatorHandle&,int) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/UnsafeList.cs:390)
0x0000013a1abfff9b (Mono JIT Code) Unity.Collections.LowLevel.Unsafe.UnsafeList`1<Unity.Entities.BakerEntityUsage/ReferencedEntityUsage>:SetCapacity (int) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/UnsafeList.cs:399)
0x0000013a1ab1ff5b (Mono JIT Code) Unity.Collections.LowLevel.Unsafe.UnsafeList`1<Unity.Entities.BakerEntityUsage/ReferencedEntityUsage>:.ctor (int,Unity.Collections.AllocatorManager/AllocatorHandle,Unity.Collections.NativeArrayOptions) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/UnsafeList.cs:181)
0x0000013a1ab1fe13 (Mono JIT Code) Unity.Entities.BakerEntityUsage:.ctor (Unity.Entities.Entity,int,Unity.Collections.Allocator) (at ./Library/PackageCache/com.unity.entities@1.0.16/Unity.Entities.Hybrid/Baking/BakerEntityUsage.cs:36)
0x0000013a1ac623b3 (Mono JIT Code) Unity.Entities.BakerState:.ctor (Unity.Entities.Entity,Unity.Collections.Allocator) (at ./Library/PackageCache/com.unity.entities@1.0.16/Unity.Entities.Hybrid/Baking/BakerState.cs:44)
0x0000013a1ac533b3 (Mono JIT Code) Unity.Entities.BakedEntityData:ApplyBakeInstructions (Unity.Entities.Baking.BakeDependencies&,Unity.Entities.Baking.IncrementalBakingContext/IncrementalBakeInstructions,Unity.Entities.BlobAssetStore,Unity.Entities.BakingSettings,Unity.Entities.Conversion.IncrementalHierarchy&,Unity.Entities.Baking.GameObjectComponents&) (at ./Library/PackageCache/com.unity.entities@1.0.16/Unity.Entities.Hybrid/Baking/BakedEntityData.cs:579)
0x0000013a1ac3094b (Mono JIT Code) Unity.Entities.BakingSystem:Bake (Unity.Entities.IncrementalBakingChangeTracker,UnityEngine.GameObject[]) (at ./Library/Pack
Found 204 leak(s) from callstack:
0x000001394105a383 (Mono JIT Code) Unity.Collections.Memory/Unmanaged/Array:Resize (void*,long,long,Unity.Collections.AllocatorManager/AllocatorHandle,long,int) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/Memory.cs:79)
0x000001394105a243 (Mono JIT Code) Unity.Collections.Memory/Unmanaged:Allocate (long,int,Unity.Collections.AllocatorManager/AllocatorHandle) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/Memory.cs:20)
0x000001394105a03b (Mono JIT Code) Unity.Collections.AllocatorManager:TryLegacy (Unity.Collections.AllocatorManager/Block&) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/AllocatorManager.cs:1023)
0x0000013941059e2b (Mono JIT Code) Unity.Collections.AllocatorManager:Try (Unity.Collections.AllocatorManager/Block&) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/AllocatorManager.cs:1055)
0x0000013941059d9b (Mono JIT Code) Unity.Collections.AllocatorManager/AllocatorHandle:Try (Unity.Collections.AllocatorManager/Block&) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/AllocatorManager.cs:540)
0x0000013941059af3 (Mono JIT Code) Unity.Collections.AllocatorManager:AllocateBlock<Unity.Collections.AllocatorManager/AllocatorHandle> (Unity.Collections.AllocatorManager/AllocatorHandle&,int,int,int) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/AllocatorManager.cs:32)
0x00000139410599bb (Mono JIT Code) Unity.Collections.AllocatorManager:Allocate<Unity.Collections.AllocatorManager/AllocatorHandle> (Unity.Collections.AllocatorManager/AllocatorHandle&,int,int,int) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/AllocatorManager.cs:53)
0x0000013a1ac60173 (Mono JIT Code) Unity.Collections.LowLevel.Unsafe.UnsafeList`1<Unity.Entities.BakerEntityUsage/ReferencedEntityUsage>:ResizeExact<Unity.Collections.AllocatorManager/AllocatorHandle> (Unity.Collections.AllocatorManager/AllocatorHandle&,int) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/UnsafeList.cs:354)
0x0000013a1ac60093 (Mono JIT Code) Unity.Collections.LowLevel.Unsafe.UnsafeList`1<Unity.Entities.BakerEntityUsage/ReferencedEntityUsage>:SetCapacity<Unity.Collections.AllocatorManager/AllocatorHandle> (Unity.Collections.AllocatorManager/AllocatorHandle&,int) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/UnsafeList.cs:390)
0x0000013a1abfff9b (Mono JIT Code) Unity.Collections.LowLevel.Unsafe.UnsafeList`1<Unity.Entities.BakerEntityUsage/ReferencedEntityUsage>:SetCapacity (int) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/UnsafeList.cs:399)
0x0000013a1ab1ff5b (Mono JIT Code) Unity.Collections.LowLevel.Unsafe.UnsafeList`1<Unity.Entities.BakerEntityUsage/ReferencedEntityUsage>:.ctor (int,Unity.Collections.AllocatorManager/AllocatorHandle,Unity.Collections.NativeArrayOptions) (at ./Library/PackageCache/com.unity.collections@2.1.4/Unity.Collections/UnsafeList.cs:181)
0x0000013a1ab1fe13 (Mono JIT Code) Unity.Entities.BakerEntityUsage:.ctor (Unity.Entities.Entity,int,Unity.Collections.Allocator) (at ./Library/PackageCache/com.unity.entities@1.0.16/Unity.Entities.Hybrid/Baking/BakerEntityUsage.cs:36)
0x0000013a1ac623b3 (Mono JIT Code) Unity.Entities.BakerState:.ctor (Unity.Entities.Entity,Unity.Collections.Allocator) (at ./Library/PackageCache/com.unity.entities@1.0.16/Unity.Entities.Hybrid/Baking/BakerState.cs:44)
0x0000013a1ac54adb (Mono JIT Code) Unity.Entities.BakedEntityData:ApplyBakeInstructions (Unity.Entities.Baking.BakeDependencies&,Unity.Entities.Baking.IncrementalBakingContext/IncrementalBakeInstructions,Unity.Entities.BlobAssetStore,Unity.Entities.BakingSettings,Unity.Entities.Conversion.IncrementalHierarchy&,Unity.Entities.Baking.GameObjectComponents&) (at ./Library/PackageCache/com.unity.entities@1.0.16/Unity.Entities.Hybrid/Baking/BakedEntityData.cs:720)
0x0000013a1ac3094b (Mono JIT Code) Unity.Entities.BakingSystem:Bake (Unity.Entities.IncrementalBakingChangeTracker,UnityEngine.GameObject[]) (at ./Library/Pack