Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 819 Bytes

component_data_from_entity.md

File metadata and controls

23 lines (17 loc) · 819 Bytes

ComponentDataFromEntity

The Entity struct identifies an entity. If you need to access ComponentData on another Entity, the only stable way of referencing that ComponentData is via the Entity ID. EntityManager provides a simple get & set ComponentData API for it.

Entity myEntity = ...;
var position = EntityManager.GetComponentData<LocalPosition>(entity);
...
EntityManager.SetComponentData(entity, position);

However, EntityManager can't be used in a C# job. ComponentDataFromEntity gives you a simple API that can also be safely used in a job.

// ComponentDataFromEntity can be automatically injected
[Inject]
ComponentDataFromEntity<LocalPosition> m_LocalPositions;

Entity myEntity = ...;
var position = m_LocalPositions[myEntity];

Back to Capsicum reference