IEntitySystem

#include

Public Types

enum SinkEventSubscriptions : uint32 {
OnBeforeSpawn = BIT(0), OnSpawn = BIT(1), OnRemove = BIT(2), OnReused = BIT(3),
Last = OnReused, Count = 4, AllSinkEvents = ~0u
}
enum EEditorSimulationMode { EEditorSimulationMode::Editing, EEditorSimulationMode::InGame, Simulation }
Determines the state of simulation in the Editor, see OnEditorSimulationModeChanged. More...

Public Member Functions

virtual void Release ()=0
Releases entity system.
virtual void PrePhysicsUpdate ()=0
virtual void Update ()=0
Updates entity system and all entities. This function executes once a frame.
virtual void Reset ()=0
Resets whole entity system, and destroy all entities.
virtual void Unload ()=0
Unloads whole entity system - should be called when level is unloaded.
virtual void PurgeHeaps ()=0
virtual void DeletePendingEntities ()=0
Deletes any pending entities (which got marked for deletion).
virtual IEntityClassRegistry * GetClassRegistry ()=0
virtual IEntity * SpawnEntity (SEntitySpawnParams &params, bool bAutoInit=true)=0
virtual bool InitEntity (IEntity *pEntity, SEntitySpawnParams &params)=0
virtual IEntity * GetEntity (EntityId id) const =0
virtual IEntity * FindEntityByName (const char *sEntityName) const =0
virtual void ReserveEntityId (const EntityId id)=0
virtual EntityId ReserveUnknownEntityId ()=0
Reserves a dynamic entity id.
virtual void RemoveEntity (EntityId entity, bool bForceRemoveNow=false)=0
virtual uint32 GetNumEntities () const =0
virtual IEntityItPtr GetEntityIterator ()=0
virtual void SendEventToAll (SEntityEvent &event)=0
virtual void OnEditorSimulationModeChanged (EEditorSimulationMode mode)=0
Sent when game mode in Editor is changed.
virtual void OnLevelLoaded ()=0
Sent after the level has finished loading.
virtual void OnLevelGameplayStart ()=0
Sent when level is loaded and gameplay can start, triggers start of simulation for entities.
virtual int QueryProximity (SEntityProximityQuery &query)=0
virtual void ResizeProximityGrid (int nWidth, int nHeight)=0
virtual int GetPhysicalEntitiesInBox (const Vec3 &origin, float radius, IPhysicalEntity **&pList, int physFlags=(1<< 1)|(1<< 2)|(1<< 3)|(1<< 4)) const =0
virtual IEntity * GetEntityFromPhysics (IPhysicalEntity *pPhysEntity) const =0
Retrieves host entity from the physical entity.
virtual void AddSink (IEntitySystemSink *sink, std::underlying_type< SinkEventSubscriptions >::type subscriptions)=0
virtual void RemoveSink (IEntitySystemSink *sink)=0
virtual void PauseTimers (bool bPause, bool bResume=false)=0
virtual bool IsIDUsed (EntityId nID) const =0
Checks whether a given entity ID is already used.
virtual void GetMemoryStatistics (ICrySizer *pSizer) const =0
Puts the memory statistics of the entities into the given sizer object according to the specifications in interface ICrySizer.
virtual ISystem * GetSystem () const =0
Gets pointer to original ISystem.
virtual bool ExtractArcheTypeLoadParams (XmlNodeRef &entityNode, SEntitySpawnParams &spawnParams) const =0
virtual bool ExtractEntityLoadParams (XmlNodeRef &entityNode, SEntitySpawnParams &spawnParams) const =0
virtual void BeginCreateEntities (int amtToCreate)=0
virtual bool CreateEntity (XmlNodeRef &entityNode, SEntitySpawnParams &pParams, EntityId &outUsingId)=0
virtual void EndCreateEntities ()=0
virtual void LoadEntities (XmlNodeRef &objectsNode, bool bIsLoadingLevelFile)=0
virtual void LoadEntities (XmlNodeRef &objectsNode, bool bIsLoadingLevelFile, const Vec3 &segmentOffest)=0
virtual void AddEntityLayerListener (const char *szLayerName, IEntityLayerListener *pListener, const bool bCaseSensitive=true)=0
Register entity layer listener.
virtual void RemoveEntityLayerListener (const char *szLayerName, IEntityLayerListener *pListener, const bool bCaseSensitive=true)=0
virtual EntityId FindEntityByGuid (const EntityGUID &guid) const =0
Finds entity by Entity GUID.
virtual IAreaManager * GetAreaManager () const =0
Gets a pointer to access to area manager.
virtual IBreakableManager * GetBreakableManager () const =0
virtual IEntityArchetype * LoadEntityArchetype (XmlNodeRef oArchetype)=0
Entity archetypes.
virtual IEntityArchetype * LoadEntityArchetype (const char *sArchetype)=0
virtual void UnloadEntityArchetype (const char *sArchetype)=0
virtual IEntityArchetype * CreateEntityArchetype (IEntityClass *pClass, const char *sArchetype)=0
virtual void RefreshEntityArchetypesInRegistry ()=0
virtual void SetEntityArchetypeManagerExtension (IEntityArchetypeManagerExtension *pEntityArchetypeManagerExtension)=0
virtual IEntityArchetypeManagerExtension * GetEntityArchetypeManagerExtension () const =0
virtual void Serialize (TSerialize ser)=0
Serializes basic entity system members (timers etc. ) to/from a savegame;.
virtual void SetNextSpawnId (EntityId id)=0
Makes sure the next SpawnEntity will use the id provided (if it's in use, the current entity is deleted).
virtual void ResetAreas ()=0
Resets any area state for the specified entity.
virtual void UnloadAreas ()=0
Unloads any area state for the specified entity.
virtual void DumpEntities ()=0
Dumps entities in system.
virtual void LockSpawning (bool lock)=0
Do not spawn any entities unless forced to.
virtual bool OnLoadLevel (const char *szLevelPath)=0
Handles entity-related loading of a level.
virtual IEntityLayer * AddLayer (const char *szName, const char *szParent, uint16 id, bool bHasPhysics, int specs, bool bDefaultLoaded)=0
Add entity layer.
virtual void LoadLayers (const char *dataFile)=0
Load layer infos.
virtual void LinkLayerChildren ()=0
Reorganize layer children.
virtual void AddEntityToLayer (const char *layer, EntityId id)=0
Add entity to entity layer.
virtual void RemoveEntityFromLayers (EntityId id)=0
Remove entity from all layers.
virtual void ClearLayers ()=0
Clear list of entity layers.
virtual void EnableDefaultLayers (bool isSerialized=true)=0
Enable all the default layers.
virtual void EnableLayer (const char *layer, bool isEnable, bool isSerialized=true)=0
Enable entity layer.
virtual void EnableLayerSet (const char *const *pLayers, size_t layerCount, bool isSerialized=true, IEntityLayerSetUpdateListener *pListener=nullptr)=0
Enable entity layers specified in the layer set and hide all other known layers.
virtual IEntityLayer * FindLayer (const char *szLayerName, const bool bCaseSensitive=true) const =0
Find a layer with a given name.
virtual bool IsLayerEnabled (const char *layer, bool bMustBeLoaded, bool bCaseSensitive=true) const =0
Is layer with given name enabled ?.
virtual bool ShouldSerializedEntity (IEntity *pEntity)=0
Returns true if entity is not in a layer or the layer is enabled/serialized.
virtual void RegisterPhysicCallbacks ()=0
Register callbacks from Physics System.
virtual void UnregisterPhysicCallbacks ()=0
virtual void PurgeDeferredCollisionEvents (bool bForce=false)=0
virtual void ResumePhysicsForSuppressedEntities (bool bWakeUp)=0
virtual void SaveInternalState (struct IDataWriteStream &writer) const =0
Save/Load internal state (used mostly for LiveCreate).
virtual void LoadInternalState (struct IDataReadStream &reader)=0
virtual int GetLayerId (const char *szLayerName) const =0
Get the layer index, -1 if not found.
virtual const char * GetLayerName (int layerId) const =0
Get the layer name, from an id.
virtual int GetLayerChildCount (const char *szLayerName) const =0
Gets the number of children for a layer.
virtual const char * GetLayerChild (const char *szLayerName, int childIdx) const =0
Gets the name of the specified child layer.
virtual int GetVisibleLayerIDs (uint8 *pLayerMask, const uint32 maxCount) const =0
Get mask for visible layers, returns layer count.
virtual void ToggleLayerVisibility (const char *layer, bool isEnabled, bool includeParent=true)=0
Toggle layer visibility (in-game only), used by LiveCreate, non recursive.
virtual void ToggleLayersBySubstring (const char *pSearchSubstring, const char *pExceptionSubstring, bool isEnable)=0
Toggle layer visibility for all layers containing pSearchSubstring with the exception of any with pExceptionSubstring.
virtual IBSPTree3D * CreateBSPTree3D (const IBSPTree3D::FaceList &faceList)=0
virtual void ReleaseBSPTree3D (IBSPTree3D *&pTree)=0
void AddEntityEventListener (EntityId entityId, EEntityEvent event, IEntityEventListener *pListener)
Registers Entity Event's listeners.
void RemoveEntityEventListener (EntityId entityId, EEntityEvent event, IEntityEventListener *pListener)

Detailed Description

Interface to the system that manages the entities in the game. Interface to the system that manages the entities in the game, their creation, deletion and upkeep. The entities are kept in a map indexed by their unique entity ID. The entity system updates only unbound entities every frame (bound entities are updated by their parent entities), and deletes the entities marked as garbage every frame before the update. The entity system also keeps track of entities that have to be drawn last and with more zbuffer resolution.

Member Enumeration Documentation

◆ EEditorSimulationMode

Determines the state of simulation in the Editor, see OnEditorSimulationModeChanged.

Enumerator
Editing

User is in editing mode.

InGame

User is in game (ctrl + g / F5)

Member Function Documentation

◆ AddSink()

virtual void IEntitySystem::AddSink ( IEntitySystemSink * sink,
std::underlying_type< SinkEventSubscriptions >::type subscriptions
)
pure virtual

Adds the sink of the entity system. The sink is a class which implements IEntitySystemSink.

Parameters
sinkPointer to the sink, must not be 0.
subscription- combination of SinkEventSubscriptions flags specifying which events to receive.

◆ BeginCreateEntities()

virtual void IEntitySystem::BeginCreateEntities ( int amtToCreate)
pure virtual

Creates entity from XML. To ensure that entity links work, call BeginCreateEntities. Before using CreateEntity, then call EndCreateEntities when you're done to setup all the links.

Parameters
entityNodeXML entity node.
spawnParamsEntity spawn parameters.
outusingIDResulting ID.

◆ ExtractArcheTypeLoadParams()

virtual bool IEntitySystem::ExtractArcheTypeLoadParams ( XmlNodeRef & entityNode,
SEntitySpawnParams & spawnParams
) const
pure virtual

Extract entity archetype load parameters from XML.

Parameters
entityNodeXML archetype entity node.
spawnParamsArchetype entity spawn parameters.

◆ ExtractEntityLoadParams()

virtual bool IEntitySystem::ExtractEntityLoadParams ( XmlNodeRef & entityNode,
SEntitySpawnParams & spawnParams
) const
pure virtual

Extract entity load parameters from XML.

Parameters
entityNodeXML entity node.
spawnParamsEntity spawn parameters.

◆ FindEntityByName()

virtual IEntity* IEntitySystem::FindEntityByName ( const char * sEntityName) const
pure virtual

Find first entity with given name.

Parameters
sEntityNameName to look for.
Returns
The entity if found, 0 if failed.
#include 

void FindEntityByName()
{
    // The name of the entity that we want to query for
    // This is the name specified with SEntitySpawnParams::sName, IEntity::SetName and in the properties panel inside the Editor when an entity is selected.
    const char* szMyEntityName = "MyEntity";

    // Query the entity system for the entity, searching the by-name entity map
    // Note that this operation is more costly than looking up by Id, and is *not* reliable as entity names are not unique!
    if (IEntity* pEntity = gEnv->pEntitySystem->FindEntityByName(szMyEntityName))
    {
        /* Entity was present in the world, and the pointer can now be used. 
           Note that the lifetime of pEntity is managed by the entity system, avoid storing the raw pointer to be safe. */
    }
}

◆ GetBreakableManager()

virtual IBreakableManager* IEntitySystem::GetBreakableManager ( ) const
pure virtual
Returns
The breakable manager interface.

◆ GetClassRegistry()

virtual IEntityClassRegistry* IEntitySystem::GetClassRegistry ( )
pure virtual

Retrieves the entity class registry interface.

Returns
Pointer to the valid entity class registry interface.

◆ GetEntity()

virtual IEntity* IEntitySystem::GetEntity ( EntityId id) const
pure virtual

Retrieves entity from its unique id.

Parameters
idUnique ID of the entity required.
Returns
Entity if one with such an ID exists, and NULL if no entity could be matched with the id
#include 
#include 

void GetEntity()
{
    // Identifier of the entity that we want to find, for example found by calling IEntity::GetId.
    // For the sake of this example we will query the default player entity identifier.
    EntityId id = LOCAL_PLAYER_ENTITY_ID;

    // Query the entity system for the entity, this will result in a constant-time lookup.
    if (IEntity* pEntity = gEnv->pEntitySystem->GetEntity(id))
    {
        /* Entity was present in the world, and the pointer can now be used. 
           Note that the lifetime of pEntity is managed by the entity system, avoid storing the raw pointer to be safe. */
    }
}

◆ GetEntityIterator()

virtual IEntityItPtr IEntitySystem::GetEntityIterator ( )
pure virtual

Gets a entity iterator. This iterator interface can be used to traverse all the entities in this entity system.

#include 

void TraverseEntities()
{
    // Retrieves an iterator that can be used to traverse all the entities in the scene
    // Note that this can easily become expensive due to the sheer number of entities that can be in each scene
    IEntityItPtr pEntityIterator = gEnv->pEntitySystem->GetEntityIterator();

    // Traverse the entities until IEntityIt::Next returns a nullptr
    while (IEntity* pEntity = pEntityIterator->Next())
    {
        // Skip entities that have been marked for deletion (clean-up will occur at the start of the next frame)
        if (!pEntity->IsGarbage())
        {
            /* pEntity can now be safely used */
        }
    }
}

◆ GetNumEntities()

virtual uint32 IEntitySystem::GetNumEntities ( ) const
pure virtual
Returns
Number of stored in entity system.

◆ GetPhysicalEntitiesInBox()

virtual int IEntitySystem::GetPhysicalEntitiesInBox ( const Vec3 & origin,
float radius,
IPhysicalEntity **& pList,
int physFlags = (1<< 1)|(1<< 2)|(1<< 3)|(1<< 4)
) const
pure virtual

Gets all entities in specified radius.

Parameters
origin
radius
pList
physFlagsIs one or more of PhysicalEntityFlag.

◆ InitEntity()

virtual bool IEntitySystem::InitEntity ( IEntity * pEntity,
SEntitySpawnParams & params
)
pure virtual

Initialize entity if entity was spawned not initialized (with bAutoInit false in SpawnEntity).

Note
Used only by Editor, to setup properties & other things before initializing entity, do not use this directly.
Parameters
pEntityPointer to just spawned entity object.
paramsEntity descriptor structure that describes what kind of entity needs to be spawned.
Returns
true if successfully initialized entity.

◆ LoadEntities()

virtual void IEntitySystem::LoadEntities ( XmlNodeRef & objectsNode,
bool bIsLoadingLevelFile
)
pure virtual

Loads entities exported from Editor. bIsLoadingLevelFile indicates if the loaded entities come from the original level file.

◆ PauseTimers()

virtual void IEntitySystem::PauseTimers ( bool bPause,
bool bResume = false
)
pure virtual

Pause all entity timers.

Parameters
bPausetrue to pause timer, false to resume.

◆ PrePhysicsUpdate()

virtual void IEntitySystem::PrePhysicsUpdate ( )
pure virtual

Updates entity system and all entities before physics is called (or as early as possible after input in the multithreaded physics case). This function executes once per frame.

◆ QueryProximity()

virtual int IEntitySystem::QueryProximity ( SEntityProximityQuery & query)
pure virtual

Get all entities within proximity of the specified bounding box.

Note
Query is not exact, entities reported can be a few meters away from the bounding box.

◆ RemoveEntity()

virtual void IEntitySystem::RemoveEntity ( EntityId entity,
bool bForceRemoveNow = false
)
pure virtual

Removes an entity by ID.

Parameters
entityId of the entity to be removed.
bForceRemoveNowIf true, forces immediately delete of entity, overwise will delete entity on next update.

◆ RemoveSink()

virtual void IEntitySystem::RemoveSink ( IEntitySystemSink * sink)
pure virtual

Removes listening sink from the entity system. The sink is a class which implements IEntitySystemSink.

Parameters
sinkPointer to the sink, must not be 0.

◆ ReserveEntityId()

virtual void IEntitySystem::ReserveEntityId ( const EntityId id)
pure virtual
Note
Might be needed to call before loading of entities to be sure we get the requested IDs.
Parameters
idMust not be 0.

◆ ResizeProximityGrid()

virtual void IEntitySystem::ResizeProximityGrid ( int nWidth,
int nHeight
)
pure virtual

Resizes the proximity grid.

Note
Call this when you know dimensions of the level, before entities are created.

◆ ResumePhysicsForSuppressedEntities()

virtual void IEntitySystem::ResumePhysicsForSuppressedEntities ( bool bWakeUp)
pure virtual

Resets physical simulation suppressed by LiveCreate during "edit mode". Called by LiveCreate subsystem when user resumed normal game mode.

◆ SendEventToAll()

virtual void IEntitySystem::SendEventToAll ( SEntityEvent & event)
pure virtual

Sends the same event to all entities in Entity System.

Parameters
eventEvent to send.

◆ SpawnEntity()

virtual IEntity* IEntitySystem::SpawnEntity ( SEntitySpawnParams & params,
bool bAutoInit = true
)
pure virtual

Spawns a new entity according to the data in the Entity Descriptor.

Parameters
paramsEntity descriptor structure that describes what kind of entity needs to be spawned.
bAutoInitIf true, automatically initialize entity.
Returns
If successful, the spawned entity, otherwise nullptr.
#include 

void SpawnEntity(const Matrix34& initialWorldTransformation)
{
    // Create a spawn parameters structure, used to specify the initial state of the entity we want to spawn
    SEntitySpawnParams spawnParameters;
    // Specify position in world coordinates
    spawnParameters.vPosition = initialWorldTransformation.GetTranslation();
    // Specify world rotation
    spawnParameters.qRotation = Quat(initialWorldTransformation);
    // Specify scale
    spawnParameters.vScale = initialWorldTransformation.GetScale();

    // Now spawn the entity in the world
    if (IEntity* pEntity = gEnv->pEntitySystem->SpawnEntity(spawnParameters))
    {
        /* pEntity can now be used, and will persist until manually removed or when the level is unloaded */
    }
}