IEntityTriggerComponent

IEntityTriggerComponentabstract

#include

Inherits IEntityComponent.

Public Member Functions

virtual void SetTriggerBounds (const AABB &bbox)=0
virtual void GetTriggerBounds (AABB &bbox)=0
virtual void ForwardEventsTo (EntityId id)=0
Forward enter/leave events to this entity.
virtual void InvalidateTrigger ()=0
Invalidate the trigger, so it gets recalculated and catches things which are already inside when it gets enabled.
- Public Member Functions inherited from IEntityComponent
virtual ICryFactory * GetFactory () const
ILINE IEntity * GetEntity () const
ILINE EntityId GetEntityId () const
IEntityComponent (IEntityComponent &&other)
IEntityComponent (const IEntityComponent &)=default
IEntityComponent & operator= (const IEntityComponent &)=default
IEntityComponent & operator= (IEntityComponent &&)=default
const CEntityComponentClassDesc & GetClassDesc () const
virtual uint64 GetEventMask () const
virtual ComponentEventPriority GetEventPriority () const
Determines the order in which this component will receive entity events (including update). Lower number indicates a higher priority.
virtual NetworkAspectType GetNetSerializeAspectMask () const
Network serialization. Override to provide a mask of active network aspects used by this component. Called once during binding to network. More...
virtual bool NetSerialize (TSerialize ser, EEntityAspects aspect, uint8 profile, int flags)
Network serialization. Will be called for each active aspect for both reading and writing. More...
virtual void NetReplicateSerialize (TSerialize ser)
virtual void NetMarkAspectsDirty (const NetworkAspectType aspects)
Call this to trigger aspect synchronization over the network. A shortcut. More...
virtual IEntityComponentPreviewer * GetPreviewer ()
Override this to return preview render interface for the component. Multiple component instances can usually share the same previewer class instance. More...
void SetComponentFlags (ComponentFlags flags)
END IEntityComponent virtual interface. More...
const ComponentFlags & GetComponentFlags () const
Return flags for this component.
ComponentFlags & GetComponentFlags ()
const CryGUID & GetGUID () const
IEntityComponent * GetParent () const
const CryTransform::CTransformPtr & GetTransform () const
Return Transformation of the entity component relative to the owning entity or parent component.
void SetTransformMatrix (const Matrix34 &transform)
Sets the transformation form a matrix. If the component doesn't have a transformation yet the function will add one.
void SetTransformMatrix (const CryTransform::CTransformPtr &transform)
Sets the transformation from another transformation. If the component doesn't have a transformation yet the function will add one.
Matrix34 GetWorldTransformMatrix () const
Return Transformation of the entity component relative to the world.
Matrix34 GetTransformMatrix () const
Return Calculated Transformation Matrix for current component transform.
const char * GetName () const
Get name of this individual component, usually only Schematyc components will have names.
void SetName (const char *szName)
int GetEntitySlotId () const
Return optional EntitySlot id used by this Component.
int GetOrMakeEntitySlotId ()
void SetEntitySlotId (int slotId)
Stores Entity slot id used by this component.
void FreeEntitySlot ()
Frees entity slot used by this component.
EEntitySimulationMode GetEntitySimulationMode () const
Return Current simulation mode of the host Entity.
void SendEvent (const SEntityEvent &event)
virtual void GetMemoryUsage (ICrySizer *pSizer) const
virtual void GameSerialize (TSerialize ser)
virtual bool NeedGameSerialize ()
virtual void LegacySerializeXML (XmlNodeRef &entityNode, XmlNodeRef &componentNode, bool bLoading)
virtual struct IEntityPropertyGroup * GetPropertyGroup ()
Only for backward compatibility to Release 5.3.0 for loading.
virtual EEntityProxy GetProxyType () const
Legacy, used for old entity proxies.

Additional Inherited Members

- Public Types inherited from IEntityComponent
typedef int ComponentEventPriority
typedef EEntityComponentFlags EFlags
typedef EntityComponentFlags ComponentFlags
- Static Public Attributes inherited from IEntityComponent
static constexpr int EmptySlotId = -1
- Protected Member Functions inherited from IEntityComponent
virtual void * QueryInterface (const CryInterfaceID &iid) const
virtual void * QueryComposite (const char *name) const
virtual void PreInit (const SInitParams &params)
virtual void Initialize ()
Called at the very first initialization of the component, at component creation time.
virtual void OnShutDown ()
Called on all Entity components right before all of the Entity Components are destructed.
virtual void OnTransformChanged ()
Called when the transformation of the component is changed.
virtual void ProcessEvent (const SEntityEvent &event)
- Protected Attributes inherited from IEntityComponent
friend IEntity
IEntity * m_pEntity = nullptr
ComponentFlags m_componentFlags
CryGUID m_guid
Unique GUID of the instance of this component.
string m_name
name of this component
CryTransform::CTransformPtr m_pTransform
Optional transformation setting for the component within the Entity object.
IEntityComponent * m_pParent = nullptr
Optional pointer to our parent component.
const CEntityComponentClassDesc * m_pClassDesc = nullptr
int m_entitySlotId = EmptySlotId
Optional Entity SlotId for storing component data like geometry of character.

Detailed Description

Interface to the trigger component, exposing support for tracking enter / leave events for other entities entering a predefined trigger box An in-game example that uses this functionality is the ProximityTrigger entity

#include 

// Example of a component that receives enter and leave events from a virtual box positioned on the entity
class CMyTriggerComponent : public IEntityComponent
{
public:
    virtual ~CMyTriggerComponent() = default;
    static void ReflectType(Schematyc::CTypeDesc& desc) { /* Reflect the component GUID in here. */ }

    virtual void Initialize() override
    {
        // Create a new IEntityTriggerComponent instance, responsible for registering our entity in the proximity grid
        IEntityTriggerComponent* pTriggerComponent = m_pEntity->CreateComponent();

        // Listen to area events in a 2m^3 box around the entity
        const Vec3 triggerBoxSize = Vec3(2, 2, 2);

        // Create an axis aligned bounding box, ensuring that we listen to events around the entity translation
        const AABB triggerBounds = AABB(triggerBoxSize * -0.5f, triggerBoxSize * 0.5f);
        // Now set the trigger bounds on the trigger component
        pTriggerComponent->SetTriggerBounds(triggerBounds);
    }

    virtual void ProcessEvent(const SEntityEvent& event) override
    {
        if (event.event == ENTITY_EVENT_ENTERAREA)
        {
            // Get the entity identifier of the entity that just entered our shape
            const EntityId enteredEntityId = static_cast(event.nParam[0]);
        }
        else if (event.event == ENTITY_EVENT_LEAVEAREA)
        {
            // Get the entity identifier of the entity that just left our shape
            const EntityId leftEntityId = static_cast(event.nParam[0]);
        }
    }

    virtual uint64 GetEventMask() const override
    {
        // Listen to the enter and leave events, in order to receive callbacks above when entities enter our trigger box
        return BIT64(ENTITY_EVENT_ENTERAREA) | BIT64(ENTITY_EVENT_LEAVEAREA);
    }
};

Member Function Documentation

◆ GetTriggerBounds()

virtual void IEntityTriggerComponent::GetTriggerBounds ( AABB & bbox)
pure virtual

Retrieve trigger bounding box in local space.

Returns
Axis aligned bounding box of the trigger in the local space.

◆ SetTriggerBounds()

virtual void IEntityTriggerComponent::SetTriggerBounds ( const AABB & bbox)
pure virtual

Creates a trigger bounding box. When physics will detect collision with this bounding box it will send an events to the entity. If entity have script OnEnterArea and OnLeaveArea events will be called.

Parameters
bboxAxis aligned bounding box of the trigger in entity local space (Rotation and scale of the entity is ignored). Set empty bounding box to disable trigger.