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 LocalTransform
s 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
LocalTransform
s in aBlobArray
and set a target index for the target'sLocalTransform
into the targeter's property,LocalTransform
s simply don't updating because they are being set only at the initialization when I assign theLocalTransform
s.I tried to update the
LocalTransform
BlobArray
in a job struct but simple I can't pass aBlobArray
into 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.Query
but 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
NativeArray
s in a singleton centralized c# class but it is not compatible with the Burst complier.
Can you help me?
Create separate
IComponentData
to hold distinct data, for example:then, to access target's position you can use
GetComponentLookup<LocalTransform>
: