Gameobject

Namespace: dmGameObject Language: C++ Type: Defold C++ File: gameobject.h Source: engine/gameobject/src/dmsdk/gameobject/gameobject.h Include: dmsdk/gameobject/gameobject.h

API for manipulating game objects

API

AcquireInstanceIndex

Type: FUNCTION Retrieve an instance index from the index pool for the collection.

Parameters

Returns

AddDynamicResourceHash

Type: FUNCTION Adds a reference to a dynamically created resource into the collection. If the resource is not released before the collection is being destroyed, the collection will automatically free the resource.

Parameters

AssignInstanceIndex

Type: FUNCTION Assign an index to the instance, only if the instance is not null.

Parameters

CreateInstanceId

Type: FUNCTION Creates a new unique instance ID and returns its hash.

Returns

CreateResult

Type: ENUM Create result enum.

Members

Delete

Type: FUNCTION Delete gameobject instance

Parameters

DeleteBones

Type: FUNCTION Recursively delete all instances flagged as bones under the given parent instance. The order of deletion is depth-first, so that the children are deleted before the parents.

Parameters

GetAbsoluteIdentifier

Type: FUNCTION Get absolute identifier relative to instance. The returned identifier is the representation of the qualified name, i.e. the path from root-collection to the sub-collection which the instance belongs to. Example: if the instance is part of a sub-collection in the root-collection named “sub” and id == “a” the returned identifier represents the path “sub.a”

Parameters

Returns

GetCollection

Type: FUNCTION Retrieve a collection from the specified instance

Parameters

Returns

GetCollectionByHash

Type: FUNCTION Retrieve a collection by socket name hash Note: in native extensions, the register can be retrieved during init using dmEngine::GetGameObjectRegister(dmExtension::AppParams *params)

Parameters

Returns

GetComponent

Type: FUNCTION Get the component, component type and its world

Parameters

Returns

GetComponentId

Type: FUNCTION Get component id from component index.

Parameters

Returns

GetComponentTypeIndex

Type: FUNCTION Get the component type index

Parameters

Returns

GetContext

Type: FUNCTION Retrieve the context for a component type

Parameters

Returns

GetIdentifier

Type: FUNCTION Get instance identifier

Parameters

Returns

GetInstanceFromIdentifier

Type: FUNCTION Get instance from identifier

Parameters

Returns

GetMessageSocket

Type: FUNCTION Retrieve the message socket for the specified collection.

Parameters

Returns

GetPosition

Type: FUNCTION Get gameobject instance position

Parameters

Returns

GetPropertyAsBool

Type: FUNCTION Retrieve a boolean property from a component.

Parameters

Returns

GetPropertyAsFloat

Type: FUNCTION Retrieve a float property from a component.

Parameters

Returns

GetPropertyAsHash

Type: FUNCTION Retrieve a hash property from a component.

Parameters

Returns

GetPropertyAsMatrix

Type: FUNCTION Retrieve a matrix4 property from a component.

Parameters

Returns

GetPropertyAsQuat

Type: FUNCTION Retrieve a quaternion property from a component.

Parameters

Returns

GetPropertyAsURL

Type: FUNCTION Retrieve a url property from a component.

Parameters

Returns

GetPropertyAsVector3

Type: FUNCTION Retrieve a vector3 property from a component.

Parameters

Returns

GetPropertyAsVector4

Type: FUNCTION Retrieve a vector4 property from a component.

Parameters

Returns

GetPropertyOptionsCount

Type: FUNCTION Get the property count from a PropertyOptions container

Parameters

Returns

GetPropertyOptionsIndex

Type: FUNCTION Get the index value from a property option at a specific index

Parameters

Returns

GetPropertyOptionsKey

Type: FUNCTION Get the key value from a property option at a specific index

Parameters

Returns

GetRotation

Type: FUNCTION Get gameobject instance rotation

Parameters

Returns

GetScale

Type: FUNCTION Get gameobject instance scale

Parameters

Returns

GetUniformScale

Type: FUNCTION Get gameobject instance uniform scale

Parameters

Returns

GetWorld

Type: FUNCTION Retrieve the world in the collection connected to the supplied component

Parameters

Returns

GetWorldMatrix

Type: FUNCTION Get game object instance world transform as Matrix4.

Parameters

Returns

GetWorldPosition

Type: FUNCTION Get gameobject instance world position

Parameters

Returns

GetWorldRotation

Type: FUNCTION Get gameobject instance world rotation

Parameters

Returns

GetWorldScale

Type: FUNCTION Get game object instance world transform

Parameters

Returns

GetWorldTransform

Type: FUNCTION Get game object instance world transform

Parameters

Returns

GetWorldUniformScale

Type: FUNCTION Get game object instance uniform scale

Parameters

Returns

HCollection

Type: TYPEDEF Gameobject collection handle

HComponent

Type: TYPEDEF Opaque handle to component instance

HComponentInternal

Type: TYPEDEF Opaque handle to internal representation of a component instance

HComponentWorld

Type: TYPEDEF Opaque handle to a component world

HInstance

Type: TYPEDEF Gameobject instance handle

HProperties

Type: TYPEDEF Gameobject properties handle

HPropertyContainer

Type: TYPEDEF Handle to a list of properties (gameobject_props.h)

HPropertyOptions

Type: TYPEDEF Handle to a list of property options

HPrototype

Type: TYPEDEF Gameobject prototype handle

HRegister

Type: TYPEDEF Collection register.

HScript

Type: TYPEDEF Script handle

HScriptInstance

Type: TYPEDEF Script instance handle

InputAction

Type: STRUCT Container of input related information.

InputResult

Type: ENUM Input result enum

Members

InstanceIdMap

Type: TYPEDEF Used for mapping instance ids from a collection definition to newly spawned instances

InstancePropertyContainers

Type: TYPEDEF Contains property containers for game objects to be spawned

INVALID_INSTANCE_POOL_INDEX

Type: CONSTANT Value for an invalid instance index, this must be the same as defined in gamesys_ddf.proto for Create#index.

IsBone

Type: FUNCTION Check whether the instance is flagged as a bone.

Parameters

Returns

New

Type: FUNCTION Create a new gameobject instance

Notes

Parameters

Returns

Playback

Type: ENUM Playback type enum

PropertyDesc

Type: STRUCT Description of a property. If the property is externally mutable, m_ValuePtr points to the value and its length is m_ElementCount. m_Variant always reflects the value.

Members

PropertyResult

Type: ENUM Property result.

Members

PropertyType

Type: ENUM Property types.

Members

PropertyValueType

Type: ENUM Type of property value

Members

PropertyVar

Type: STRUCT Property variant that holds the data for a variable

Members

Result

Type: ENUM Result enumeration.

Members

SceneNode

Type: STRUCT Opaque struct that holds info about the current node

Notes

SceneNodeIterator

Type: STRUCT Opaque struct that holds info about the current position when traversing the scene

SceneNodeProperty

Type: STRUCT Struct that holds info about the current position when traversing the scene

Members

m_Number
[type:double] floating point number
m_Hash
[type:dmhash_t] The hashed value.
m_URL
[type:char[1024]] The text representation of the url (if reverse hashes are enabled)
m_V4
[type:float[4]] Used for Vector3, Vector4 and Quat
m_Bool
[type:bool] A boolean value
m_Text
[type:const char*] Text from a text property

SceneNodePropertyIterator

Type: STRUCT Holds the property

Members

SceneNodePropertyType

Type: ENUM scene node property types

Notes

Members

SetBone

Type: FUNCTION Set whether the instance should be flagged as a bone. Instances flagged as bones can have their transforms updated in a batch through SetBoneTransforms. Used for animated skeletons.

Parameters

SetBoneTransforms

Type: FUNCTION Set the local transforms recursively of all instances flagged as bones, starting with component with id. The order of the transforms is depth-first.

Parameters

Returns

SetIdentifier

Type: FUNCTION Set instance identifier. Must be unique within the collection.

Parameters

Returns

SetPosition

Type: FUNCTION Set gameobject instance position

Parameters

SetPropertyFromBool

Type: FUNCTION Sets the value of a boolean property on a component.

Parameters

Returns

SetPropertyFromHash

Type: FUNCTION Sets the value of a hash property on a component.

Parameters

Returns

SetPropertyFromHash

Type: FUNCTION Sets the value of a float property on a component.

Parameters

Returns

SetPropertyFromMatrix4

Type: FUNCTION Sets the value of a matrix4 property on a component.

Parameters

Returns

SetPropertyFromQuat

Type: FUNCTION Sets the value of a quaternion property on a component.

Parameters

Returns

SetPropertyFromURL

Type: FUNCTION Sets the value of a URL property on a component.

Parameters

Returns

SetPropertyFromVector3

Type: FUNCTION Sets the value of a vector3 property on a component.

Parameters

Returns

SetPropertyFromVector4

Type: FUNCTION Sets the value of a vector4 property on a component.

Parameters

Returns

SetRotation

Type: FUNCTION Set gameobject instance rotation

Parameters

SetScale

Type: FUNCTION Set gameobject instance uniform scale

Parameters

SetScale

Type: FUNCTION Set gameobject instance non-uniform scale

Parameters

SetScaleXY

Type: FUNCTION Set gameobject instance x and y scale

Parameters

Spawn

Type: FUNCTION Spawns a new gameobject instance. The actual creation is performed after the update is completed.

Parameters

TraverseGetRoot

Type: FUNCTION Gets the top node of the whole game (the main collection)

Notes

Parameters

Returns

Examples

The following examples show how to iterate over currently loaded scene graph

void OutputNode(dmGameObject::SceneNode* node) {
    dmGameObject::SceneNodeIterator it = dmGameObject::TraverseIterateChildren(node);
    while(dmGameObject::TraverseIterateNext(&it))
    {
        OutputProperties(&it.m_Node); // see dmGameObject::TraverseIterateProperties()
        OutputNode(&it.m_Node);
    }
}

bool OutputScene(HRegister regist) {
    dmGameObject::SceneNode root;
    if (!dmGameObject::TraverseGetRoot(regist, &root))
        return false;
    OutputNode(&node);
}

TraverseIterateChildren

Type: FUNCTION Get a scene node iterator for the nodes’ children

Parameters

Returns

TraverseIterateNext

Type: FUNCTION Step a scene node iterator to the next sibling

Parameters

Returns

TraverseIterateProperties

Type: FUNCTION Create a scene node traversal property iterator

Notes

Parameters

Returns

Examples

The following examples show how to iterate over the properties of a node

dmGameObject::SceneNodePropertyIterator pit = TraverseIterateProperties(node);
while(dmGameObject::TraverseIteratePropertiesNext(&pit))
{
    const char* name = dmHashReverseSafe64(pit.m_Property.m_NameHash);
    switch(pit.m_Property.m_Type)
    {
    case dmGameObject::SCENE_NODE_PROPERTY_TYPE_NUMBER: ...
    ...
    }
}

TraverseIteratePropertiesNext

Type: FUNCTION Steps the scene node traversal property iterator to the next property

Parameters

Returns

UpdateContext

Type: STRUCT Update context

Members

UpdateResult

Type: ENUM Update result enum.

Members