Cry::Entity

Cry::Entity Namespace Reference

Typedefs

using EntityEventMask = uint64

Enumerations

enum EEvent {
EEvent::TransformChanged, EEvent::TransformChangeDone, EEvent::TimerExpired, EEvent::Initialize,
EEvent::Remove, EEvent::Reset, EEvent::ChildAttached, EEvent::AttachedToParent,
EEvent::ChildDetached, EEvent::DetachedFromParent, EEvent::LinkAdded, EEvent::LinkRemoved,
EEvent::Hidden, EEvent::Unhidden, EEvent::LayerHidden, EEvent::LayerUnhidden,
EEvent::PhysicsToggled, EEvent::PhysicsStateChanged, EEvent::LuaScriptEvent, EEvent::OtherEntityEnteredArea,
EEvent::OtherEntityLeftArea, EEvent::OtherEntityEnteredNearArea, EEvent::OtherEntityLeftNearArea, EEvent::OtherEntityMoveInsideArea,
EEvent::OtherEntityMoveNearArea, EEvent::PhysicsThreadPostStep, EEvent::PhysicalObjectBroken, EEvent::PhysicsCollision,
EEvent::PhysicsThreadCollision, EEvent::RenderVisibilityChanged, EEvent::LevelLoaded, EEvent::LevelStarted,
EEvent::GameplayStarted, EEvent::EnterLuaScriptState, EEvent::LeaveLuaScriptState, EEvent::DeserializeSaveGameStart,
EEvent::DeserializeSaveGameDone, EEvent::BecomeInvisible, EEvent::BecomeVisible, EEvent::OverrideMaterialChanged,
EEvent::MaterialLayerChanged, EEvent::AnimationEvent, EEvent::LuaScriptSetColliderMode, EEvent::ActivateFlowNodeOutput,
EEvent::EditorPropertyChanged, EEvent::ReloadLuaScript, EEvent::SubscribedForUpdates, EEvent::UnsubscribedFromUpdates,
EEvent::NetworkAuthorityChanged, EEvent::BecomeLocalPlayer, EEvent::AddToRadar, EEvent::RemoveFromRadar,
EEvent::NameChanged, EEvent::AudioTriggerStarted, EEvent::AudioTriggerEnded, EEvent::SlotChanged,
EEvent::PhysicalTypeChanged, EEvent::NetworkReplicatedFromServer, EEvent::PrePhysicsUpdate, EEvent::Update,
EEvent::Last
}
EEvent defines all events that can be sent to an entity. More...

Functions

constexpr EntityEventMask EventToMask (EEvent event)

Detailed Description

Main namespace for the entity system Note that moving entity types under this namespace is still early in the works!

Enumeration Type Documentation

◆ EEvent

enum Cry::Entity::EEvent
strong

EEvent defines all events that can be sent to an entity.

Enumerator
TransformChanged

Sent when the entity local or world transformation matrix change (position/rotation/scale). nParam[0] = combination of the EEntityXFormFlags.

TransformChangeDone

Called when the entity is moved/scaled/rotated in the editor. Only send on mouseButtonUp (hence finished).

TimerExpired

Sent when the entity timer expire. nParam[0] = TimerId, nParam[1] = milliseconds.

Initialize

Sent for unremovable entities when they are respawn.

Remove

Sent before entity is removed.

Reset

Sent to reset the state of the entity (used from Editor). nParam[0] is 1 if entering game mode, 0 if exiting

ChildAttached

Sent to parent entity after child entity have been attached. nParam[0] contains ID of child entity.

AttachedToParent

Sent to child entity after it has been attached to the parent. nParam[0] contains ID of parent entity.

ChildDetached

Sent to parent entity after child entity have been detached. nParam[0] contains ID of child entity.

DetachedFromParent

Sent to child entity after it has been detached from the parent. nParam[0] contains ID of parent entity.

LinkAdded

Sent to an entity when a new named link was added to it (normally through the Editor)

See also
IEntity::GetEntityLinks
IEntity::AddEntityLink nParam[0] contains IEntityLink ptr.
LinkRemoved

Sent to an entity when a named link was removed from it (normally through the Editor)

See also
IEntity::RemoveEntityLink nParam[0] contains IEntityLink ptr.
Hidden

Sent when the entity must be hidden.

Unhidden

Sent when the entity must become not hidden.

LayerHidden

Sent when the entity must be hidden.

LayerUnhidden

Sent when the entity must become not hidden.

PhysicsToggled

Sent when a physics processing for the entity must be enabled/disabled. nParam[0] == 1 physics must be enabled if 0 physics must be disabled.

PhysicsStateChanged

Sent when a physics in an entity changes state. nParam[0] == 1 physics entity awakes, 0 physics entity get to a sleep state.

LuaScriptEvent

Sent when script is broadcasting its events. nParam[0] = Pointer to the ASCIIZ string with the name of the script event. nParam[1] = Type of the event value from IEntityClass::EventValueType. nParam[2] = Pointer to the event value depending on the type.

OtherEntityEnteredArea

Sent when triggering entity enters to the area proximity, this event sent to all target entities of the area. nParam[0] = TriggerEntityId, nParam[1] = AreaId, nParam[2] = EntityId of Area

OtherEntityLeftArea

Sent when triggering entity leaves the area proximity, this event sent to all target entities of the area. nParam[0] = TriggerEntityId, nParam[1] = AreaId, nParam[2] = EntityId of Area

OtherEntityEnteredNearArea

Sent when triggering entity is near to the area proximity, this event sent to all target entities of the area. nParam[0] = TriggerEntityId, nParam[1] = AreaId, nParam[2] = EntityId of Area fParam[0] = distance

OtherEntityLeftNearArea

Sent when triggering entity leaves the near area within proximity region of the outside area border. nParam[0] = TriggerEntityId, nParam[1] = AreaId, nParam[2] = EntityId of Area

OtherEntityMoveInsideArea

Sent when triggering entity moves inside the area within proximity region of the outside area border. nParam[0] = TriggerEntityId, nParam[1] = AreaId, nParam[2] = EntityId of Area

OtherEntityMoveNearArea

Sent when triggering entity moves inside the area within the near region of the outside area border. nParam[0] = TriggerEntityId, nParam[1] = AreaId, nParam[2] = EntityId of Area, fParam[0] = FadeRatio (0-1)

PhysicsThreadPostStep

Sent when an entity with pef_monitor_poststep receives a poststep notification (the hamdler should be thread safe!) fParam[0] = time interval

PhysicalObjectBroken

Sent when Breakable object is broken in physics.

PhysicsCollision

Sent when a logged physical collision is processed on the Main thread. The collision has already occurred since this event is logged, but can be handled on the main thread without considering threading. nParam[0] = const EventPhysCollision *, contains collision info and can be obtained as: reinterpret_cast(event.nParam[0]) nParam[1] 0 if we are the source of the collision, otherwise 1.

#include 

// Example of how a component can listen to collision events
// Note that this example assumes that the entity has already been physicalized
class CPhysicsMonitorCompoent final : public IEntityComponent
{
public:
    // Provide a virtual destructor, ensuring correct destruction of IEntityComponent members
    virtual ~CPhysicsMonitorCompoent() = default;

    static void ReflectType(Schematyc::CTypeDesc& desc) { /* Reflect type here */ }

    virtual void ProcessEvent(const SEntityEvent& event) override
    {
        if (event.event == ENTITY_EVENT_COLLISION)
        {
            // Get the EventPhysCollision structure describing the collision that occurred
            const EventPhysCollision* pPhysCollision = reinterpret_cast(event.nParam[0]);

            // The EventPhysCollision provides information for both the source and target entities
            // Therefore, we store the indices of this entity (and the other collider)
            // This can for example be used to get the surface identifier (and thus the material) of the part of our entity that collided
            const int thisEntityIndex = static_cast(event.nParam[1]);
            // Calculate the index of the other entity
            const int otherEntityIndex = (thisEntityIndex + 1) % 2;

            // Get the contact point (in world coordinates) of the two entities
            const Vec3& contactPoint = pPhysCollision->pt;
            // Get the collision normal vector
            const Vec3& contactNormal = pPhysCollision->n;

            // Get properties for our entity, starting with the local velocity of our entity at the contact point
            const Vec3& relativeContactVelocity = pPhysCollision->vloc[thisEntityIndex];
            // Get the mass of our entity
            const float contactMass = pPhysCollision->mass[thisEntityIndex];
            // Get the identifier of the part of our entity that collided
            // This is the same identifier that is added with IPhysicalEntity::AddGeometry
            const int contactPartId = pPhysCollision->partid[thisEntityIndex];
            // Get the surface on our entity that collided
            const int contactSurfaceId = pPhysCollision->idmat[thisEntityIndex];
            // Get the ISurfaceType representation of the surface that collided
            if (const ISurfaceType* pContactSurface = gEnv->p3DEngine->GetMaterialManager()->GetSurfaceType(contactSurfaceId))
            {
                /* Interact with pContactSurface here*/
            }
        }
    }

    virtual uint64 GetEventMask() const override
    {
        // Indicate that we want to receive the ENTITY_EVENT_COLLISION entity event
        return ENTITY_EVENT_BIT(ENTITY_EVENT_COLLISION);
    }
};
PhysicsThreadCollision

Sent when a physical collision is reported just as it occurred, most likely on the physics thread. This callback has to be thread-safe! nParam[0] = const EventPhysCollision *, contains collision info and can be obtained as: reinterpret_cast(event.nParam[0]) nParam[1] 0 if we are the source of the collision, otherwise 1.

RenderVisibilityChanged

Sent only if ENTITY_FLAG_SEND_RENDER_EVENT is set Called when entity is first rendered (When any of the entity render nodes are considered by 3D engine for rendering this frame) Or called when entity is not being rendered for at least several frames nParam[0] == 0 if rendeing Stops. nParam[0] == 1 if rendeing Starts.

LevelLoaded

Called when the level loading is complete.

LevelStarted

Called when the level is started.

GameplayStarted

Called when the game is started (games may start multiple times).

EnterLuaScriptState

Called when the entity enters a script state.

LeaveLuaScriptState

Called when the entity leaves a script state.

DeserializeSaveGameStart

Called before we serialized the game from file.

DeserializeSaveGameDone

Called after we serialized the game from file.

BecomeInvisible

Called when the entity becomes invisible. nParam[0] = if 1 physics will ignore this event

BecomeVisible

Called when the entity gets out of invisibility. nParam[0] = if 1 physics will ignore this event

OverrideMaterialChanged

Called when the entity material change. nParam[0] = pointer to the new IMaterial.

MaterialLayerChanged

Called when the entitys material layer mask changes.

AnimationEvent

Called when an animation event (placed on animations in editor) is encountered. nParam[0] = AnimEventInstance* pEventParameters. nParam[1] = ICharacterInstance* that this event occurred on

LuaScriptSetColliderMode

Called from ScriptBind_Entity when script requests to set collidermode. nParam[0] = ColliderMode

ActivateFlowNodeOutput

Called to activate some output in a flow node connected to the entity nParam[0] = Output port index nParam[1] = TFlowInputData* to send to output

EditorPropertyChanged

Called in the editor when a property of the selected entity changes. This is not sent when using IEntityPropertyGroup nParam[0] = IEntityComponent pointer or nullptr nParam[1] = Member id of the changed property, (

See also
IEntityComponent::GetClassDesc() FindMemberById(nParam[1]))
ReloadLuaScript

Called when a script reloading is requested and done in the editor.

SubscribedForUpdates

Called when the entity is added to the list of entities that are updated. Note that this event is deprecated, and should not be used

UnsubscribedFromUpdates

Called when the entity is removed from the list of entities that are updated. Note that this event is deprecated, and should not be used

NetworkAuthorityChanged

Called when the entity's network authority changes. Only the server is able to delegate/revoke the authority to/from the client. nParam[0] stores the new authority value.

BecomeLocalPlayer

Sent once to the to the client when the special player entity has spawned.

See also
ENTITY_FLAG_LOCAL_PLAYER
AddToRadar

Called when the entity should be added to the radar.

RemoveFromRadar

Called when the entity should be removed from the radar.

NameChanged

Called when the entity's name is set.

AudioTriggerStarted

Called when an event related to an audio trigger occurred. REMARK:: Only sent for triggers that have their ERequestFlags set to receive Callbacks via (CallbackOnExternalOrCallingThread | DoneCallbackOnExternalThread) from the main-thread nParam[0] stores a const CryAudio::SRequestInfo* const

AudioTriggerEnded

Remark: Will also be sent, if the trigger failed to start.

SlotChanged

Sent when an entity slot changes, i.e. geometry was added nParam[0] stores the slot index

PhysicalTypeChanged

Sent when the physical type of an entity changed, i.e. physicalized or dephysicalized.

NetworkReplicatedFromServer

Entity was just spawned on this machine as requested by the server.

PrePhysicsUpdate

Called when the pre-physics update is done; fParam[0] is the frame time.

Update

Sent when the entity is updating every frame. nParam[0] = pointer to SEntityUpdateContext structure. fParam[0] = frame time

Last

Last entity event in list.