Hi I want to separate the entity behaviors in detail as possible (if i can…)
for example a homing missile which accelerates has two functions**(homing, accelerating)**
so i want to make AccelerateSystem, GuidingSystem.
and each systems have jobs like below
i’m using Entities 1.0.0-pre.44 version.
[StructLayout(LayoutKind.Auto)]
public partial struct GuidingSystemJob : IJobEntity
{
public EntityCommandBuffer.ParallelWriter ECB_Parallel;
[ReadOnly] public float DeltaTime;
[BurstCompile]
public void Execute(Entity entity, GuidingCompData guidingData, in PhysicsVelocity physicsVelocity, [EntityIndexInQuery] int sortKey)
{
var newPhysicsVelocity = physicsVelocity
... Do Rotate newPhysicsVelocity To Target Here
ECB_Parallel.SetComponent(sortKey, entity, newPhysicsVelocity);
ECB_Parallel.SetComponent(sortKey, entity, guidingData);
}
}
public partial struct AccelerateSystemJob : IJobEntity
{
public EntityCommandBuffer.ParallelWriter ECB_Parallel;
[ReadOnly] public float DeltaTime;
[BurstCompile]
public void Execute(Entity entity, AccelerateCompData accelerateData, in PhysicsVelocity physicsVelocity, [EntityIndexInQuery] int sortKey)
{
var newPhysicsVelocity = physicsVelocity;
... Do Accelerating newPhysicsVelocity Here
ECB_Parallel.SetComponent(sortKey, entity, newPhysicsVelocity);
ECB_Parallel.SetComponent(sortKey, entity, accelerateDat);
}
}
//================================================================================
public partial struct GuidingSystem : ISystem
{
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
if (SystemAPI.TryGetSingleton<EndSimulationEntityCommandBufferSystem.Singleton>(out var EndSimulatorECBSystem) == false)
return;
var ECB = EndSimulatorECBSystem.CreateCommandBuffer(state.WorldUnmanaged);
var deltaTime = state.WorldUnmanaged.Time.DeltaTime;
JobHandle jobHandle;
jobHandle = new GuidingSystemJob
{
ECB_Parallel = ECB.AsParallelWriter(),
DeltaTime = deltaTime,
}.ScheduleParallel(state.Dependency);
state.Dependency = jobHandle;
}
}
AcceleratingSystem is almost identical to GuidingSystem
The problem is when the jobs executes, PhyscisVelocity data is equal on Guiding and Accelerating.
and the latest PhysicsVelocity data registered in ECB will be written to the entity component.
i also tried separating each systems to different system groups like (InitializationSystemGroup, SimulationSystemGroup, PresentationSystemGroup)
i thought ECB play backs would be called on end of System Groups.
i must be misunderstanding the whole system
So is there any method to make it work?
i know i can just merge both function into a single job or make the code unscheduled and run procedurally.
that will solve the problem.
but i am figuring out a way to keep my code organized in detail and performant