Hello (I am not sure if its in the right forum if its not please inform me where to reopen),
I recently started to work with ECS and the job-system but I’ve encountered some issues.
when i try to move an entity array by translation nothing happens.
if some one can give me a tip why it doesn’t work ill be really grateful.
here is the piece of code:
public class SpreadCardsSystem : JobComponentSystem
{
[RequireComponentTag(typeof(MyCards))]
struct SendCardsToPosJob : IJobForEachWithEntity<Rotation, MyCards, Translation>
{
[DeallocateOnJobCompletion] [ReadOnly] public NativeArray<CardWithPos> eCards;
public EntityCommandBuffer.Concurrent entityCommandBuffer;
public void Execute(Entity entity, int index, ref Rotation rotation, ref MyCards myCards, ref Translation translation)
{
translation.Value = eCards[index].position;
rotation.Value.value.z = 90f;
entityCommandBuffer.SetComponent(index, eCards[index].entity, translation);
}
}
private EndSimulationEntityCommandBufferSystem endSimulationEntityCommandBufferSystem;
protected override void OnCreate()
{
endSimulationEntityCommandBufferSystem = World.GetOrCreateSystem<EndSimulationEntityCommandBufferSystem>();
base.OnCreate();
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
JobHandle jobHandle = new JobHandle();
try
{
EntityQuery entityQuery = GetEntityQuery(typeof(MyCards), ComponentType.ReadOnly<Translation>());
NativeArray<Entity> arr = entityQuery.ToEntityArray(Allocator.TempJob);
if (arr.Length == 0)
{
arr.Dispose();
return jobHandle;
}
else
Debug.Log(arr.Length.ToString());
NativeArray<CardWithPos> enemyCardWithPosArr = new NativeArray<CardWithPos>(arr.Length, Allocator.TempJob);
for (int i = 0; i < arr.Length; i++)
{
enemyCardWithPosArr = new CardWithPos
{
entity = arr,
position = new float3(4f + (-2 * i),-3f,0)
};
}
arr.Dispose();
SendCardsToPosJob sendCardsJob = new SendCardsToPosJob
{
eCards = enemyCardWithPosArr
};
enemyCardWithPosArr.Dispose();
jobHandle = sendCardsJob.Schedule(this, inputDeps);
endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(jobHandle);
}
catch (System.Exception)
{
}
return jobHandle;
}
}