I am trying to make a simple AI logic that has 3 states; Idle, Chase, Attack. In Idle state human entities should set their targets, in Chase state they will chase and ultimately Attack. I made it but with searching within double foreach loop and it isn't performant.
So I decided to hold a cache of all human's id's and LocalTransforms and set the target id to the targeter. This way I wanted to be able to get the target position with just positions[targetIndex].
If I store the
LocalTransforms in aBlobArrayand set a target index for the target'sLocalTransforminto the targeter's property,LocalTransforms simply don't updating because they are being set only at the initialization when I assign theLocalTransforms.I tried to update the
LocalTransformBlobArrayin a job struct but simple I can't pass aBlobArrayinto the job struct (it says"InvalidOperationException: HumanFindTargetJob.JobData.arrayAspect.Value._Data uses unsafe Pointers which is not allowed.") and I don't want to make it on the main thread.I tried to do the things with
SystemAPI.Querybut I can't get a reference and send the query to the job and to get the query I must do it in a system.I tried to hold the properties in separate
NativeArrays in a singleton centralized c# class but it is not compatible with the Burst complier.
Can you help me?
Create separate
IComponentDatato hold distinct data, for example:then, to access target's position you can use
GetComponentLookup<LocalTransform>: