Hey, I have a system that fires bullets in every entity which have BurstPointComponent but the problem is I had to wait between each shot, so I had to save a duration for everyone of them. To do so, I’ve created another component called FireDurationComponent and attached it to same entities as well. I could have use only the BurstPointComponent but to change it’s ShootDuration value I had to get a new instance because I cannot change a property of a nativearray element ( Such as positions*.Value = float3.zero)*
But I’ve been facing a weird problem. I suspect it is because of how jobs are distributed. The thing is, one of the burst points shoot just fine but the other one doesn’t shoot with the same rate(despite their values are equal for test purposes) Such as this (even I disable second burstpoint on right handside which is weird)
My entire repo:
My Job Struct:
[RequireComponentTag(typeof(BurstPointComponent))]
struct EnemyShootingJob : IJobChunk
{
[ReadOnly] public EntityCommandBuffer CommandBuffer;
[ReadOnly] public ArchetypeChunkComponentType<LocalToWorld> PositionType;
public ArchetypeChunkComponentType<FireDurationComponent> FireDurationType;
[ReadOnly] public ArchetypeChunkComponentType<BurstPointComponent> BurstPointType;
[ReadOnly] public float DeltaTime;
public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
{
var positions = chunk.GetNativeArray(PositionType);
var burstPoints = chunk.GetNativeArray(BurstPointType);
var fireDurations = chunk.GetNativeArray(FireDurationType);
for (var i = 0; i < burstPoints.Length; i++)
{
var position = positions[i];
var burstPoint = burstPoints[i];
var fireDuration = fireDurations[i];
//FAILS BECAUSE, SOME OF THEM RUNS ON A DIFFERENT THREAD, SO IT WON'T BE EQUAL ?
if (fireDurations[i].FireDuration <= burstPoints[i].ShootRate)
{
fireDurations[i] = new FireDurationComponent
{
FireDuration = fireDuration.FireDuration + DeltaTime
};
}
else
{
fireDurations[i] = new FireDurationComponent { };
var entity = CommandBuffer.Instantiate(burstPoint.Bullet);
Translation localToWorld = new Translation
{
Value = new float3(position.Value.c3.x, position.Value.c3.y, position.Value.c3.z)
};
CommandBuffer.SetComponent(entity, localToWorld);
PhysicsVelocity velocity = new PhysicsVelocity
{
Linear = new float3(0f, 0f, 20f),
Angular = float3.zero
};
CommandBuffer.SetComponent(entity, velocity);
}
}
}
}
And I am also receiving errors like that: