For each frame, I need to compute the directions of my units based on the Position and LinearVelocity of all other units. (Similar to the swarm (boid) simulation).
If I allocate a NativeArray like the one below, can I assume they are in the same order?
Furthermore, how do I get access to a LinearVelocity component? It is part of the RigidBodyAspect but I cannot use it to fill a NativeArray.
NativeArray<LocalTransform> localTransformMemory = m_WalkingAgents.ToComponentDataArray<LocalTransform>(Allocator.TempJob);
NativeArray<Physics.LinearVelocity> localVelocityMemory = m_WalkingAgents.ToComponentDataArray<LocalTransform>(Allocator.TempJob);
If that assumption does not hold. How do I best create a data structure that allows me to create a copy of these two types of data efficiently.
Other approaches could be:
- Using a
NativeParallelHashMap<>for each data type withEntityas the key. I am not sure how an efficient data allocation would look, similar toToComponentDataArray. - Create another data type in that someone combines the elements.