Reputation: 7
I'm trying to do the following:
private void AssignPlayer()
{
EntityQuery playerQuery = GetEntityQuery(ComponentType.ReadOnly<PlayerTag>());
Entity playerEntity = playerQuery.ToEntityArray(Allocator.Temp);
Entities.
WithAll<ChaserTag>().
ForEach((ref TargetData targetData) =>
{
if (playerEntity != Entity.Null)
{
targetData.targetEntity = playerEntity;
}
}).Schedule();
}
But the line that assigns targetData.targetEntity = playerEntity;
throws the error:
Cannot implicitly convert type 'Unity.Collections.NativeArray<Unity.Entities.Entity>' to 'Unity.Entities.Entity'
Upvotes: 0
Views: 1799
Reputation: 1637
if( playerQuery.CalculateEntityCount()!=0 )
{
NativeArray<Entity> players = playerQuery.ToEntityArray( Allocator.TempJob );
Entities.WithName("targetData_update_job")
.WithReadOnly( players ).WithDeallocateOnJobCompletion( players )
.WithAll<ChaserTag>()
.ForEach( ( ref TargetData targetData ) =>
{
targetData.targetEntity = players[0];
}
).ScheduleParallel();
}
else Debug.LogWarning($"{nameof(AssignPlayer)}(): no players tho");
Upvotes: 1