EntitiesMap
A NativeHashMap<Entity, uint> on PhysicsStructuresComponent. It maps a body’s main entity to its index in BodiesList.
Use EntitiesMap when you have an Entity and need the corresponding native body index — for example when resolving static-map entries or looking up a slot in collision buffers.
Key and value
| Key | PhysicsBodyData.Main — the root entity for the body (from PhysicsBodyComponent). For kinematic or static triggers this may be a parent entity, not the collider entity itself. |
| Value | uint body index — the same index stored in PhysicsBodyUpdateComponent.Index and used to index BodiesList, Randoms, Collisions, and related buffers. |
Only entities imported this frame appear in the map. Indices are 0 … ActiveBodiesCount - 1.
Lifecycle
Bootstrap allocates EntitiesMap with capacity MaxEntitiesCount.
Each frame in LateSimulation, ImportPhysicsDataSystem:
ClearBodiesJob— clears the hash map together withBodiesList.ImportPhysicsDataJob— for each active body, writesBodiesList[entityInQueryIndex]and callsEntitiesMap.TryAdd(bodyData.Main, (uint)entityInQueryIndex).
The map is rebuilt from scratch every import. Do not cache indices across frames without also reading PhysicsBodyUpdateComponent.Index or re-querying the map after import.
Custom jobs that receive an Entity and need simulation data should TryGetValue on EntitiesMap, then index BodiesList or collision buffers with the returned index.
if (structures.EntitiesMap.TryGetValue(bodyEntity, out uint bodyIndex))
{
var body = structures.BodiesList[(int)bodyIndex];
// ...
}
If
TryGetValuefails, the entity was not imported this frame (disabled, overMaxEntitiesCount, or missing required components).
Related
- BodiesList — array indexed by map values
- PhysicsBodyData —
Mainfield is the map key - CollisionMapSingleton —
StaticMapstores entities; detection resolves them viaEntitiesMap