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:

  1. ClearBodiesJob — clears the hash map together with BodiesList.
  2. ImportPhysicsDataJob — for each active body, writes BodiesList[entityInQueryIndex] and calls EntitiesMap.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 TryGetValue fails, the entity was not imported this frame (disabled, over MaxEntitiesCount, or missing required components).


This site uses Just the Docs, a documentation theme for Jekyll.