Class SpaceEntity

Nested Relationships

Nested Types

Class Documentation

class SpaceEntity

Primary multiplayer object that can have associated scripts and many multiplayer components created within it.

Public Types

typedef std::function<void(SpaceEntity*, SpaceEntityUpdateFlags, csp::common::Array<ComponentUpdateInfo>&)> UpdateCallback
typedef std::function<void(bool)> DestroyCallback
typedef std::function<void(bool)> CallbackHandler
typedef std::function<void(SpaceEntity*)> EntityCreatedCallback

Public Functions

SpaceEntity()

Creates a default instance of a SpaceEntity.

SpaceEntity(SpaceEntitySystem *InEntitySystem)

Creates a SpaceEntity instance using the space entity system provided.

SpaceEntity(SpaceEntitySystem *EntitySystem, SpaceEntityType Type, uint64_t Id, const csp::common::String &Name, const SpaceTransform &Transform, uint64_t OwnerId, bool IsTransferable, bool IsPersistent)

Internal constructor to explicitly create a SpaceEntity in a specified state.

Initially implemented for use in SpaceEntitySystem::CreateAvatar

~SpaceEntity()

Destroys the SpaceEntity instance.

uint64_t GetId() const

Get the ID of this SpaceEntity, this is generated by the endpoints and should be unique to each Entity.

Returns

The uint64_t ID of the SpaceEntity.

uint64_t GetOwnerId() const

Get the ClientID of the owner of the SpaceEntity.

This starts as the user that creates the Entity but can change if another user patches the Entity.

Returns

the uint64_t ClientID of the owner of the SpaceEntity.

const csp::common::String &GetName() const

Get the name set for this SpaceEntity.

Returns

Name.

void SetName(const csp::common::String &Value)

Set the name of the SpaceEntity.

Parameters

Valuecsp::common::String : The name to set.

const SpaceTransform &GetTransform() const

Get the SpaceTransform of the SpaceEntity.

Returns

SpaceTransform.

SpaceTransform GetGlobalTransform() const

Get the Global SpaceTransform of the SpaceEntity, derived from it’s parent.

Returns

SpaceTransform.

const csp::common::Vector3 &GetPosition() const

Get the position of the SpaceEntity, in world space.

Returns

Position.

csp::common::Vector3 GetGlobalPosition() const

Get the Global position of the SpaceEntity, in world space, derived from it’s parent.

Returns

Position.

void SetPosition(const csp::common::Vector3 &Value)

Set the position of the SpaceEntity, in world space.

Parameters

Valuecsp::common::Vector3 : The position to set.

const csp::common::Vector4 &GetRotation() const

Get the rotation of the SpaceEntity.

Returns

Rotation.

csp::common::Vector4 GetGlobalRotation() const

Get the Global rotation of the SpaceEntity, derived from it’s parent.

Returns

Rotation.

void SetRotation(const csp::common::Vector4 &Value)

Set the rotation of the SpaceEntity.

Parameters

Valuecsp::common::Vector4 : The rotation to set.

const csp::common::Vector3 &GetScale() const

Get the scale of the SpaceEntity.

Returns

Scale.

csp::common::Vector3 GetGlobalScale() const

Get the Global scale of the SpaceEntity, derived from it’s parent.

Returns

Scale.

void SetScale(const csp::common::Vector3 &Value)

Set the scale of the SpaceEntity.

Parameters

Valuecsp::common::Vector3 : The scale to set.

bool GetIsTransient() const

Get whether the space is transient or persistent.

Returns

returns True if the space is transient and false if it is marked as persistent.

const csp::common::String &GetThirdPartyRef() const

Get the third party reference of this entity.

Returns

A string representing the third party reference set for this entity.

void SetThirdPartyRef(const csp::common::String &InThirdPartyRef)

Set the third party reference for this entity.

Parameters

InThirdPartyRefcsp::common::String : The third party reference to set.

csp::systems::EThirdPartyPlatform GetThirdPartyPlatformType() const

Get the third party platform type of this entity.

Returns

A string representing third party platform type set for this entity.

void SetThirdPartyPlatformType(const csp::systems::EThirdPartyPlatform InThirdPartyPlatformType)

Set third party platform type for this entity.

Parameters

InThirdPartyPlatformTypecsp::systems::EThirdPartyPlatform : The third party platform type to set.

SpaceEntityType GetEntityType() const

Get the type of the Entity.

Returns

The SpaceEntityType enum value.

SpaceEntitySystem *GetSpaceEntitySystem()

Get SpaceEntitySystem Object.

Returns

SpaceEntitySystem

void SetParentId(uint64_t ParentId)

Sets the parent for this entity QueueUpdate() should be called afterwards to enable changes to the parent.

Parameters

ParentId – uint64_t The new parent id of this entity.

void RemoveParentEntity()

Removes the parent entity QueueUpdate() should be called afterwards to enable changes to the parent.

SpaceEntity *GetParentEntity() const

Gets the parent of this entity.

Returns

SpaceEntity

void CreateChildEntity(const csp::common::String &InName, const SpaceTransform &InSpaceTransform, EntityCreatedCallback Callback)

Create a new entity with this entity as it’s parent.

Parameters
const csp::common::List<SpaceEntity*> *GetChildEntities() const

Gets the children of this entity.

Returns

csp::common::List<SpaceEntity>

void QueueUpdate()

Queues an update which will be executed on next Tick() or ProcessPendingEntityOperations(). Not a blocking or async function.

void Destroy(CallbackHandler Callback)

Sends a patch message with a flag to destroy the entity.

Will remove the entity from endpoints and signal remote clients to delete the entity. Note this will trigger local deletion of the SpaceEntity immediately, without considering if remotes were able to also delete. If the endpoint fails to process this message, the client that called this function will be out of sync. It is advised to handle this situation by dropping the client out of a space if the callback comes back as failed.

Parameters

CallbackCallbackHandler : The callback triggers when the patch message completes, either successfully or unsuccessfully.

void SetUpdateCallback(UpdateCallback Callback)

Set a callback to be executed when a patch message is received for this Entity.

Only one callback can be set.

Parameters

CallbackUpdateCallback : Contains the SpaceEntity that updated, a set of flags to tell which parts updated and an array of information to tell which components updated. When this callback is received, the flags and arrays should be used to determine which properties have updated data.

void SetDestroyCallback(DestroyCallback Callback)

Set a callback to be executed when a patch message with a destroy flag is received for this Entity.

Only one callback can be set.

Parameters

CallbackDestroyCallback : Contains a bool that is true if the Entity is being deleted.

void SetPatchSentCallback(CallbackHandler Callback)

Set a callback to be executed when a patch message queued for the entity is sent.

Only one callback can be set.

Parameters

CallbackCallbackHandler : Contains a bool that is true when the patch message is sent.

const csp::common::Map<uint16_t, ComponentBase*> *GetComponents() const

Get the map of components on this SpaceEntity.

Returns

A map of components indexed with the component ID.

ComponentBase *GetComponent(uint16_t Key)

Get a component on this SpaceEntity by the specified key.

Parameters

Key – uint16_t : The component ID for the desired component.

Returns

The component if found or nullptr if not found.

ComponentBase *AddComponent(ComponentType Type)

Add a component of the given type.

Parameters

TypeComponentType : The type of component to add.

Returns

The newly created component.

void RemoveComponent(uint16_t Key)

Remove a component of the given key.

Note that the component cannot currently truly be removed from the server data, the best we can do is add a blank component in its place, which clients decide to ignore when retrieving data.

Parameters

Key – uint16_t : The component ID of the component to remove.

EntityScript &GetScript()

Gets the script associated with the space entity.

Returns

The EntityScript instance set on the entity.

bool IsSelected() const

Returns the selection state of the entity.

Returns

Selection state of the entity, Selected = True, Deselected = False.

uint64_t GetSelectingClientID() const

Retrieve the ClientID for the Selecting Client.

Returns

The client ID of the selecting client. Deselected Entity = 0.

bool Select()

Select the Entity.

Only works if the Entity is currently deselected.

Returns

True if selection occurred. False if not.

bool Deselect()

Deselect the Entity.

Only works if:

  • The Entity is currently selected

  • The Client attempting to deselect has the same ClientID as the one who selected it

Returns

True if deselection occurred. False if not.

bool IsModifiable() const

Checks if the entity can be modified.

Specifically whether the local client already owns the entity or can take ownership of the entity.

Returns

True if the entity can be modified, False if not.

void Lock()

Locks the entity if it hasn’t been locked already.

Pre

The entity must not already be locked. A CSP error will be sent to the LogSystem if this condition is not met.

Post

This internally sets the lock type as a dirty property. This entity should now be replicated, to process the change.

void Unlock()

Unlocks the entity if the entity is locked.

Pre

The entity must be locked. A CSP error will be sent to the LogSystem if this condition is not met.

Post

This internally sets the lock type as a dirty property. This entity should now be replicated, to process the change.

bool IsLocked() const

Checks if the entity has a lock type other than LockType::None, set by calling SpaceEntity::Lock.

Returns

bool

UpdateCallback GetEntityUpdateCallback()

Getter for the EntityUpdateCallback.

Returns

: UpdateCallback

void SetEntityUpdateCallbackParams(SpaceEntity *Entity, SpaceEntityUpdateFlags Flags, csp::common::Array<ComponentUpdateInfo> &Info)

Setter for the parameters of the EntityUpdateCallback.

Parameters
DestroyCallback GetEntityDestroyCallback()

Getter for the EntityDestroyCallback.

Returns

: DestroyCallback

void SetEntityDestroyCallbackParams(const bool Boolean)

Setter for the parameters of the EntityDestroyCallbackParams.

Parameters

bool – : the boolean to set

CallbackHandler GetEntityPatchSentCallback()

Getter for the EntityPatchSentCallback.

Returns

: CallbackHandler

void SetEntityPatchSentCallbackParams(const bool Boolean)

Setter for the parameters of the EntityPatchSentCallbackParams.

Parameters

bool – : the boolean to set

csp::common::Map<uint16_t, ReplicatedValue> GetDirtyProperties()

Getter for the dirty properties.

Returns

csp::common::Map<uint16_t, ReplicatedValue>

csp::common::List<uint16_t> GetTransientDeletionComponentIds()

Getter for the transient deletion component IDs.

Returns

csp::common::List<uint16_t>

bool GetShouldUpdateParent()

Getter for the ShouldUpdateParent boolean.

Returns

bool

void SetShouldUpdateParent(const bool Boolean)

Setter for the ShouldUpdateParent boolean.

Parameters

Boolean – bool : the boolean value to set ShouldUpdateParent to

SpaceEntity *GetParent()

Getter for the parent entity.

Returns

SpaceEntity*

csp::common::Optional<uint64_t> GetParentId()

Getter for the parent id.

Returns

csp::common::Optional<uint64_t>

std::chrono::milliseconds GetTimeOfLastPatch()

Getter for the time of the last patch.

Returns

std::chrono::milliseconds

void RemoveParentFromChildEntity(size_t Index)

Remove the parent from the specified child entity.

Parameters

Index – size_t : the index of the child entity

void MarkForUpdate()

Mark for update.

EntityScriptInterface *GetScriptInterface()

Getter for the script interface.

Returns

EntityScriptInterface*

void ClaimScriptOwnership()

Claim script ownership.

void ApplyLocalPatch(bool InvokeUpdateCallback = true)

Apply a local patch.

Parameters

InvokeUpdateCallback – bool : whether to invoke the update callback (default: true)

void ResolveParentChildRelationship()

Resolve the relationship between the parent and the child.

csp::common::Map<uint16_t, DirtyComponent> GetDirtyComponents()

Getter for the dirty components.

Returns

csp::common::Map<uint16_t, DirtyComponent>

void AddDirtyComponent(ComponentBase *DirtyComponent)

Add specified dirty component to space entity.

Parameters

DirtyComponent – ComponentBase* : the dirty component to add

void OnPropertyChanged(ComponentBase *DirtyComponent, int32_t PropertyKey)

Update after the property of a component was changed.

Parameters
  • DirtyComponent – ComponentBase* : the dirty component to update

  • PropertyKey – int32_t : the key of the property to update