Heya, so I’ve created a random movement system for a project:
using Unity.Collections;
using Unity.Core;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
public partial class AgentMoveSystem : SystemBase
{
protected override void OnUpdate()
{
float deltaTime = World.Time.DeltaTime;
Random rnd = new Random();
rnd.InitState(49500);
AgentSpawnSettings settings = EntityManager.GetComponentData<AgentSpawnSettings>(SystemAPI.GetSingletonEntity<AgentSpawnSettings>());
float3 minPos = settings.MinPos;
float3 maxPos = settings.MaxPos;
Entities
.ForEach((ref MovementAgent agent, ref LocalTransform localTransform) =>
{
localTransform.Position =
new float3(localTransform.Position.x + rnd.NextFloat(), localTransform.Position.y + rnd.NextFloat(), localTransform.Position.z);
if (localTransform.Position.y < minPos.y) localTransform.Position =
new float3(localTransform.Position.x, maxPos.y, localTransform.Position.z);
if (localTransform.Position.y > maxPos.y) localTransform.Position =
new float3(localTransform.Position.x, minPos.y, localTransform.Position.z);
if (localTransform.Position.x < minPos.x) localTransform.Position =
new float3(maxPos.x, localTransform.Position.y, localTransform.Position.z);
if (localTransform.Position.x > maxPos.x) localTransform.Position =
new float3(minPos.x, localTransform.Position.y, localTransform.Position.z);
}).ScheduleParallel(); //no difference between Run(), Schedule() and ScheduleParallel()
}
}
The issue is that Run(), Schedule() and ScheduleParallel() all have the same performance. There are 200000 MovementAgent entities with a total of 7 different AgentFlag IComponentData (AgentFlagOne, AgentFlagTwo, AgentFlagThree and so on)
Given that my CPU has 8 physical cores, I’d expect it to be around 80% utilized. But it’s not, and there’s no performance difference between the three different methods.
What am I missing? Appreciate any help.