Ok, so… I am beyond frustrated.
I have two sets of Entities; Autos and Roads. I have a Job that is designed to move the cars along the points of the road.
The job executes based on an AutoTag component (and has the Auto’s Transform, the car’s current RoadIdentity and LaneIdentity) During the job I need to loop through the Road Entities (which is passed to the job via a NativeArray) Thing is, when I attempt to get the component’s data I am getting errors. (I have walked away from my development system out of frustration, so atm I don’t have the exact error message)
So basically I am attempting to understand how to access other entities and their data within a job. Thoughts?
using System.Collections;
using System.Collections.Generic;
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;
public class ER3D_TrafficControlSystem : JobComponentSystem
{
[BurstCompile]
[RequireComponentTag(typeof(ERAutoTag))]
private struct AutoNaviationJob : IJobForEachWithEntity<
HoverCarLevelComponent,
HoverCarSpeedComponent,
RoadIdentityComponent,
LaneIdentityComponent,
CurrentPositionIndexComponent,
Translation>
{
[DeallocateOnJobCompletionAttribute]
[ReadOnly]
public NativeArray<Entity> roadEntities;
public float deltaTime;
public void Execute(
Entity entity,
int index,
ref HoverCarLevelComponent carLevel,
ref HoverCarSpeedComponent carSpeed,
ref RoadIdentityComponent carRoadIdentity,
ref LaneIdentityComponent carLaneIdentity,
ref CurrentPositionIndexComponent currentPositionIndex,
ref Translation translation)
{
//EntityManager entityManager = World.Active.EntityManager;
translation.Value.z += 1;
for (int i = 0; i < roadEntities.Length; i++)
{
Entity roadEntity = roadEntities[i];
//var rI = ComponentDataFromEntity<IdentityComponent>(roadEntity);
//var roadIdentity = GetComponentData<IdentityComponent>(roadEntity);
//var roadIdentity = entityManager.GetComponentData<IdentityComponent>(roadEntity);
//var laneIdentity = entityManager.GetComponentData<LaneIdentityComponent>(roadEntity);
// if (roadIdentity.value == carRoadIdentity.value &&
// laneIdentity.value == carLaneIdentity.value)
// {
// //translation.Value.z += 1;
// break;
// }
}
}
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
var entityManager = World.Active.EntityManager;
EntityQuery allRoadsQuery = GetEntityQuery(
typeof(ERRoadTag),
ComponentType.ReadOnly<IdentityComponent>(),
ComponentType.ReadOnly<LaneIdentityComponent>(),
ComponentType.ReadOnly<LanePointsComponent>());
NativeArray<Entity> entityArray = allRoadsQuery.ToEntityArray(Allocator.TempJob);
AutoNaviationJob autoNaviationJob = new AutoNaviationJob
{
roadEntities = entityArray,
deltaTime = Time.deltaTime
};
JobHandle jobHandle = autoNaviationJob.Schedule(this, inputDeps);
return jobHandle;
}
}