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()

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 persistant.

Returns

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

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.

const 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
  • InNamecsp::common::String : The name to give the new SpaceEntity.

  • InSpaceTransformSpaceTransform : The initial transform to set the SpaceEntity to.

  • Callback – EntityCreatedCallback : A callback that executes when the creation is complete, which contains a pointer to the new SpaceEntity so that it can be used on the local client.

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

Callback – CallbackHandler : 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

Callback – UpdateCallback : 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 recieved, 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

Callback – DestroyCallback : 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

Callback – CallbackHandler : 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

Type – ComponentType : 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.

void SerialisePatch(IEntitySerialiser &Serialiser) const

Serialise local changes into patch message format into the given serialiser.

Does not send a patch.

Parameters

SerialiserIEntitySerialiser : The serialiser to use.

void Serialise(IEntitySerialiser &Serialiser)

Serialise the entire SpaceEntity into object message format into the given serialiser.

Does not send a message.

Parameters

SerialiserIEntitySerialiser : The serialiser to use.

void SerialiseComponent(IEntitySerialiser &Serialiser, ComponentBase *Component) const

Serialises a given component into a consistent format for the given serialiser.

Parameters
void Deserialise(IEntityDeserialiser &Deserialiser)

Using the given deserialiser, populate the SpaceEntity with the data in the deserialiser.

Parameters

DeserialiserIEntityDeserialiser : The deserialiser to use.

csp::multiplayer::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()

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.