Represents a component that can be attached to an individual entity instance Allows for populating entities with custom game logic. More...
#include
Inherits ICryUnknown, and ISimpleEntityEventListener.
Inherited by IClipVolumeComponent, IEntityAreaComponent, IEntityAttributesComponent, IEntityAudioComponent, IEntityBehaviorTreeComponent, IEntityCameraComponent, IEntityCoverUserComponent, IEntityDynamicResponseComponent, IEntityFactionComponent, IEntityFlowGraphComponent, IEntityListenerComponent, IEntityNavigationComponent, IEntityObservableComponent, IEntityObserverComponent, IEntityRopeComponent, IEntityScriptComponent, IEntitySubstitutionComponent, IEntityTriggerComponent, IGeometryEntityComponent, and IParticleEntityComponent.
Classes | |
struct | SInitParams |
SInitParams is only used from Schematyc to call PreInit to initialize Schematyc Entity Component. More... | |
Public Types | |
typedef int | ComponentEventPriority |
typedef EEntityComponentFlags | EFlags |
typedef EntityComponentFlags | ComponentFlags |
Public Member Functions | |
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. | |
Protected Member Functions | |
virtual void * | QueryInterface (const CryInterfaceID &iid) const |
virtual void * | QueryComposite (const char *name) const |
virtual void | PreInit (const SInitParams ¶ms) |
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 | |
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. | |
Represents a component that can be attached to an individual entity instance Allows for populating entities with custom game logic.
#include
class CMinimalComponent final : public IEntityComponent
{
public:
// Provide a virtual destructor, ensuring correct destruction of IEntityComponent members
virtual ~CMinimalComponent() = default;
// Reflect type to set a unique identifier for this component
// and provide additional information to expose it in the sandbox
static void ReflectType(Schematyc::CTypeDesc& desc)
{
// Provide a globally unique identifier for the component, can be generated in Visual Studio via Tools -> Create GUID (in registry format).
desc.SetGUID("{35EC6526-3D24-4376-9509-806908FF4698}"_cry_guid);
desc.SetEditorCategory("MyComponents");
desc.SetLabel("MyComponent");
}
};
|
inline virtual |
SaveGame serialization. Override to specify what to serialize in a saved game.
ser | Serializing stream. Use IsReading() to decide read/write phase. Use Value() to read/write a property. |
|
inline |
Return ClassDesc for this component Class description is storing runtime C++ class reflection information It contain information about member variables of the component and how to serialize them, information how to create an instance of class and all relevant additional information to handle this class.
|
inline virtual |
Return bit mask of the EEntityEvent flags that we want to receive in ProcessEvent (ex: BIT64(ENTITY_EVENT_HIDE) | BIT64(ENTITY_EVENT_UNHIDE)) Only events matching the returned bit mask will be sent to the ProcessEvent method
#include
class CMyEventComponent final : public IEntityComponent
{
public:
// Provide a virtual destructor, ensuring correct destruction of IEntityComponent members
virtual ~CMyEventComponent() = default;
static void ReflectType(Schematyc::CTypeDesc& desc) { /* Reflect the component GUID in here. */}
// Override the ProcessEvent function to receive the callback whenever an event specified in GetEventMask is triggered
virtual void ProcessEvent(const SEntityEvent& event) override
{
// Check if this is the update event
if (event.event == ENTITY_EVENT_UPDATE)
{
// The Update event provides delta time as the first floating-point parameter
const float frameTime = event.fParam[0];
/* Handle update logic here */
}
}
// As an optimization, components have to specify a bitmask of the events that they want to handle
// This is called once at component creation, and then only if IEntity::UpdateComponentEventMask is called, to support dynamic change of desired events (useful for disabling update when you don't need it)
virtual uint64 GetEventMask() const override { return BIT64(ENTITY_EVENT_UPDATE); }
};
|
inline |
Return GUID of this component. This GUID is only guaranteed to be unique within the host entity, different entities can have components with equal GUIDs. Each component in the entity have type guid (GetClassDesc().GetGUID()) (ex: identify EntityLightComponent class) and a unique instance guid IEntityComponent::GetGUID() (ex: identify Light01,Light02,etc.. component)
|
inline virtual |
Network serialization. Override to provide a mask of active network aspects used by this component. Called once during binding to network.
#include
class CMyNetSerializedComponent final : public IEntityComponent
{
public:
// Provide a virtual destructor, ensuring correct destruction of IEntityComponent members
virtual ~CMyNetSerializedComponent() = default;
static void ReflectType(Schematyc::CTypeDesc& desc) { /* Reflect the component GUID in here. */}
// Define the aspect / stream to use for this aspect, in our case we want a server stream since only the server can change health
static constexpr EEntityAspects HealthAspect = eEA_GameServerA;
// Override GetNetSerializeAspectMask to specify that we will handle HealthAspect
virtual NetworkAspectType GetNetSerializeAspectMask() const override { return HealthAspect; }
// Override NetSerialize, called on the server when the aspect has been marked dirty, and then on the client to read the data
virtual bool NetSerialize(TSerialize ser, EEntityAspects aspect, uint8 profile, int flags) override
{
// Check that we are processing the desired aspect
if (aspect == HealthAspect)
{
// Serialize health, either to network (on the server) or from network (on a client)
ser.Value("health", m_health);
}
}
// Helper utility that game code should call to set the health of this component
void SetHealth(float newHealth)
{
CRY_ASSERT_MESSAGE(gEnv->bServer, "Health can only be modified on the server!");
// Update the local state
m_health = newHealth;
// Notify the network that the health aspect has changed
// This will result in NetSerialize being called to serialize data over the network
NetMarkAspectsDirty(HealthAspect);
}
protected:
float m_health = 100.f;
};
ILINE int IEntityComponent::GetOrMakeEntitySlotId | ( | ) |
Return optional EntitySlot id used by this Component If slot id is not allocated, new slotid will be allocated and returned
|
inline |
Return Parent component, only used by Schematyc components Initialized by the PreInit call
|
inline virtual |
Override this to return preview render interface for the component. Multiple component instances can usually share the same previewer class instance.
|
inline virtual |
Optionally serialize component to/from XML. For user-facing properties, see GetProperties.
|
inline virtual |
SaveGame serialization. Override to enable serialization for the component.
|
virtual |
Call this to trigger aspect synchronization over the network. A shortcut.
#include
class CMyNetSerializedComponent final : public IEntityComponent
{
public:
// Provide a virtual destructor, ensuring correct destruction of IEntityComponent members
virtual ~CMyNetSerializedComponent() = default;
static void ReflectType(Schematyc::CTypeDesc& desc) { /* Reflect the component GUID in here. */}
// Define the aspect / stream to use for this aspect, in our case we want a server stream since only the server can change health
static constexpr EEntityAspects HealthAspect = eEA_GameServerA;
// Override GetNetSerializeAspectMask to specify that we will handle HealthAspect
virtual NetworkAspectType GetNetSerializeAspectMask() const override { return HealthAspect; }
// Override NetSerialize, called on the server when the aspect has been marked dirty, and then on the client to read the data
virtual bool NetSerialize(TSerialize ser, EEntityAspects aspect, uint8 profile, int flags) override
{
// Check that we are processing the desired aspect
if (aspect == HealthAspect)
{
// Serialize health, either to network (on the server) or from network (on a client)
ser.Value("health", m_health);
}
}
// Helper utility that game code should call to set the health of this component
void SetHealth(float newHealth)
{
CRY_ASSERT_MESSAGE(gEnv->bServer, "Health can only be modified on the server!");
// Update the local state
m_health = newHealth;
// Notify the network that the health aspect has changed
// This will result in NetSerialize being called to serialize data over the network
NetMarkAspectsDirty(HealthAspect);
}
protected:
float m_health = 100.f;
};
|
inline virtual |
Used to match an entity's state when it is replicated onto a remote machine. This is called once when spawning an entity, in order to serialize its data - and once again on the remote client to deserialize the state. Deserialization will always occur before IEntityComponent::Initialize is called.
[in,out] | ser | Serializer for reading / writing values. |
#include
class CMyReplicatedComponent final : public IEntityComponent
{
public:
static void ReflectType(Schematyc::CTypeDesc& desc) { /* Reflect the component GUID in here. */}
// Implement NetReplicateSerialize, called on the server when an entity with the component is spawned
virtual void NetReplicateSerialize(TSerialize ser) override
{
ser.Value("health", m_health);
}
void SetHealth(float health) { m_health = health; }
protected:
float m_health = 100.f;
};
void SpawnEntityOnAllClients()
{
CRY_ASSERT(gEnv->bServer);
// Spawn a new entity, but do *not* automatically initialize it
// This is delayed as want to add our component before network replication occurs
if (IEntity* pEntity = gEnv->pEntitySystem->SpawnEntity(SEntitySpawnParams(), false))
{
// Create an instance of our component and attach it to the entity
CMyReplicatedComponent* pComponent = pEntity->CreateComponentClass();
// Change the initial health, as an example of replication a new state on the remote clients
pComponent->SetHealth(0.f);
// Now initialize the entity, resulting in CMyComponent::NetReplicateSerialize first being called on the server (this instance) to write the data to network, and then on all clients to deserialize.
gEnv->pEntitySystem->InitEntity(pEntity, SEntitySpawnParams());
}
}
|
inline virtual |
Network serialization. Will be called for each active aspect for both reading and writing.
[in,out] | ser | Serializer for reading/writing values. |
[in] | aspect | The number of the aspect being serialized. |
[in] | profile | Can be ignored, used by CryPhysics only. |
[in] | flags | Can be ignored, used by CryPhysics only. |
#include
class CMyNetSerializedComponent final : public IEntityComponent
{
public:
// Provide a virtual destructor, ensuring correct destruction of IEntityComponent members
virtual ~CMyNetSerializedComponent() = default;
static void ReflectType(Schematyc::CTypeDesc& desc) { /* Reflect the component GUID in here. */}
// Define the aspect / stream to use for this aspect, in our case we want a server stream since only the server can change health
static constexpr EEntityAspects HealthAspect = eEA_GameServerA;
// Override GetNetSerializeAspectMask to specify that we will handle HealthAspect
virtual NetworkAspectType GetNetSerializeAspectMask() const override { return HealthAspect; }
// Override NetSerialize, called on the server when the aspect has been marked dirty, and then on the client to read the data
virtual bool NetSerialize(TSerialize ser, EEntityAspects aspect, uint8 profile, int flags) override
{
// Check that we are processing the desired aspect
if (aspect == HealthAspect)
{
// Serialize health, either to network (on the server) or from network (on a client)
ser.Value("health", m_health);
}
}
// Helper utility that game code should call to set the health of this component
void SetHealth(float newHealth)
{
CRY_ASSERT_MESSAGE(gEnv->bServer, "Health can only be modified on the server!");
// Update the local state
m_health = newHealth;
// Notify the network that the health aspect has changed
// This will result in NetSerialize being called to serialize data over the network
NetMarkAspectsDirty(HealthAspect);
}
protected:
float m_health = 100.f;
};
|
inline protected virtual |
Only called by system classes to initalize component. Users must not call this method directly
|
inline protected virtual |
By overriding this function component will be able to handle events sent from the host Entity. Requires returning the desired event flag in GetEventMask.
event | Event structure, contains event id and parameters. |
#include
class CMyEventComponent final : public IEntityComponent
{
public:
// Provide a virtual destructor, ensuring correct destruction of IEntityComponent members
virtual ~CMyEventComponent() = default;
static void ReflectType(Schematyc::CTypeDesc& desc) { /* Reflect the component GUID in here. */}
// Override the ProcessEvent function to receive the callback whenever an event specified in GetEventMask is triggered
virtual void ProcessEvent(const SEntityEvent& event) override
{
// Check if this is the update event
if (event.event == ENTITY_EVENT_UPDATE)
{
// The Update event provides delta time as the first floating-point parameter
const float frameTime = event.fParam[0];
/* Handle update logic here */
}
}
// As an optimization, components have to specify a bitmask of the events that they want to handle
// This is called once at component creation, and then only if IEntity::UpdateComponentEventMask is called, to support dynamic change of desired events (useful for disabling update when you don't need it)
virtual uint64 GetEventMask() const override { return BIT64(ENTITY_EVENT_UPDATE); }
};
|
inline |
Send event to this specific component, first checking if the component is interested in the event
event | description |
receiving | component |
|
inline |
END IEntityComponent virtual interface.
Set flags for this component
|
inline |
Set a new name for this component Names of the components must not be unique
|
protected |
Reflected type description for this component Contain description of the reflected member variables