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
Type: FUNCTION Retrieve an instance index from the index pool for the collection.
Parameters
collection (dmGameObject::HColleciton) - Collection from which to retrieve the instance index.Returns
instance (uint32_t) - index from the index pool of collection.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
collection (HCollection) - Collection handlepath_hash (dmhash_t) - resource path hashType: FUNCTION Assign an index to the instance, only if the instance is not null.
Parameters
index (uint32_t) - The index to assign.instance (dmGameObject::HInstance) - The instance that should be assigned the index.Type: FUNCTION Creates a new unique instance ID and returns its hash.
Returns
id (dmhash_t) - hash of the new unique instance idType: ENUM Create result enum.
Members
dmGameObject::CREATE_RESULT_OKdmGameObject::CREATE_RESULT_UNKNOWN_ERRORType: FUNCTION Delete gameobject instance
Parameters
collection (dmGameObject::HCollection) - Gameobject collectioninstance (dmGameObject::HInstance) - Gameobject instancerecursive (bool) - If true, delete child hierarchy recursively in child to parent order (leaf first)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
parent (HInstance) - Parent instance of the hierarchyType: 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
instance (dmGameObject::HInstance) - Gameobject instance to get absolute identifier toidentifier (const char*) - Identifier relative to instanceReturns
return (dmhash_t) - Absolute identifier.Type: FUNCTION Retrieve a collection from the specified instance
Parameters
instance (dmGameObject::HInstance) - Game object instanceReturns
collection (dmGameObject::HInstance) - The collection the specified instance belongs toType: 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
regist (dmGameObject::HRegister) - Registersocket_name (dmhash_t) - The socket nameReturns
collection (dmGameObject::HCollection) - The collection if successful. 0 otherwise.Type: FUNCTION Get the component, component type and its world
Parameters
instance (dmGameObject::HInstance) - Instancecomponent_id (dmhash_t) - Component idcomponent_type (uint32_t*) - (out) Component type. Used for validation.component (HComponent*) - (out) The component.world (HComponentWorld*) - (out) The component world. May be 0.Returns
result (dmGameObject::Result) - RESULT_OK if the component was foundType: FUNCTION Get component id from component index.
Parameters
instance (dmGameObject::HInstance) - Instancecomponent_index (uint16_t) - Component indexcomponent_id (dmhash_t*) - Component id as out-argumentReturns
result (dmGameObject::Result) - RESULT_OK if the component was foundType: FUNCTION Get the component type index
Parameters
collection (HCollection) - Collection handletype_hash (dmhash_t) - The hashed name of the registered component type (e.g. dmHashString(“guic”))Returns
type_index (uint32_t) - The component type index. 0xFFFFFFFF if not foundType: FUNCTION Retrieve the context for a component type
Parameters
collection (HCollection) - Collection handlecomponent_type_index (uint32_t) - index of the component typeReturns
context (void*) - The pointer to the context, 0x0 if not foundType: FUNCTION Get instance identifier
Parameters
instance (dmGameObject::HInstance) - Gameobject instanceReturns
return (dmhash_t) - Identifier. dmGameObject::UNNAMED_IDENTIFIER if not set.Type: FUNCTION Get instance from identifier
Parameters
collection (dmGameObject::HCollection) - Collectionidentifier (dmhash_t) - IdentifierReturns
instance (dmGameObject::HInstance) - Instance. NULL if instance isn’t found.Type: FUNCTION Retrieve the message socket for the specified collection.
Parameters
collection (dmGameObject::HCollection) - Collection handleReturns
socket (dmMessage::HSocket) - The message socket of the specified collectionType: FUNCTION Get gameobject instance position
Parameters
instance (dmGameObject::HInstance) - Gameobject instanceReturns
return (dmVMath::Point3) - PositionType: FUNCTION Retrieve a boolean property from a component.
Parameters
instance (HInstance) - Instance of the game objectcomponent_id (dmhash_t) - Id of the componentproperty_id (dmhash_t) - Id of the propertyout_value (bool*) - The retrieved property valueReturns
PROPERTY_RESULT_OK - if the out-parameter was writtenType: FUNCTION Retrieve a float property from a component.
Parameters
instance (HInstance) - Instance of the game objectcomponent_id (dmhash_t) - Id of the componentproperty_id (dmhash_t) - Id of the propertyout_value (float*) - The retrieved property valueReturns
PROPERTY_RESULT_OK - if the out-parameter was writtenType: FUNCTION Retrieve a hash property from a component.
Parameters
instance (HInstance) - Instance of the game objectcomponent_id (dmhash_t) - Id of the componentproperty_id (dmhash_t) - Id of the propertyout_value (dmhash_t*) - The retrieved property valueReturns
PROPERTY_RESULT_OK - if the out-parameter was writtenType: FUNCTION Retrieve a matrix4 property from a component.
Parameters
instance (HInstance) - Instance of the game objectcomponent_id (dmhash_t) - Id of the componentproperty_id (dmhash_t) - Id of the propertyout_value (dmGameObject::Matrix4*) - The retrieved property valueReturns
PROPERTY_RESULT_OK - if the out-parameter was writtenType: FUNCTION Retrieve a quaternion property from a component.
Parameters
instance (HInstance) - Instance of the game objectcomponent_id (dmhash_t) - Id of the componentproperty_id (dmhash_t) - Id of the propertyout_value (dmVMath::Quat*) - The retrieved property valueReturns
PROPERTY_RESULT_OK - if the out-parameter was writtenType: FUNCTION Retrieve a url property from a component.
Parameters
instance (HInstance) - Instance of the game objectcomponent_id (dmhash_t) - Id of the componentproperty_id (dmhash_t) - Id of the propertyout_value (dmMessage::URL*) - The retrieved property valueReturns
PROPERTY_RESULT_OK - if the out-parameter was writtenType: FUNCTION Retrieve a vector3 property from a component.
Parameters
instance (HInstance) - Instance of the game objectcomponent_id (dmhash_t) - Id of the componentproperty_id (dmhash_t) - Id of the propertyout_value (dmVMath::Vector3*) - The retrieved property valueReturns
PROPERTY_RESULT_OK - if the out-parameter was writtenType: FUNCTION Retrieve a vector4 property from a component.
Parameters
instance (HInstance) - Instance of the game objectcomponent_id (dmhash_t) - Id of the componentproperty_id (dmhash_t) - Id of the propertyout_value (dmVMath::Vector4*) - The retrieved property valueReturns
PROPERTY_RESULT_OK - if the out-parameter was writtenType: FUNCTION Get the property count from a PropertyOptions container
Parameters
options (HPropertyOptions) - Options handleReturns
count (uint32_t) - The number of property optionsType: FUNCTION Get the index value from a property option at a specific index
Parameters
options (HPropertyOptions) - Options handleoptions_index (int32_t) - The options index into the property options containerresult (int32_t*) - If the option at the index is valid, store the result. Pointer is untouched otherwiseReturns
PROPERTY_RESULT_OK - if the property option at the index is validType: FUNCTION Get the key value from a property option at a specific index
Parameters
options (HPropertyOptions) - Options handleoptions_index (int32_t) - The options index into the property options containerresult (dmhash_t*) - If the option at the index is valid, store the result. Pointer is untouched otherwiseReturns
PROPERTY_RESULT_OK - if the property option at the index is validType: FUNCTION Get gameobject instance rotation
Parameters
instance (dmGameObject::HInstance) - Gameobject instanceReturns
return (dmGameObject::Quat) - rotationType: FUNCTION Get gameobject instance scale
Parameters
instance (dmGameObject::HInstance) - Gameobject instanceReturns
return (dmGameObject::Vector3) - Non-uniform scaleType: FUNCTION Get gameobject instance uniform scale
Parameters
instance (dmGameObject::HInstance) - Gameobject instanceReturns
return (float) - Uniform scaleType: FUNCTION Retrieve the world in the collection connected to the supplied component
Parameters
collection (HCollection) - Collection handlecomponent_type_index (uint32_t) - index of the component typeReturns
world (void*) - The pointer to the world, 0x0 if not foundType: FUNCTION Get game object instance world transform as Matrix4.
Parameters
instance (dmGameObject::HInstance) - Gameobject instanceReturns
return (dmGameObject::Matrix4) - World transform matrix.Type: FUNCTION Get gameobject instance world position
Parameters
instance (dmGameObject::HInstance) - Gameobject instanceReturns
return (dmGameObject::Point3) - World positionType: FUNCTION Get gameobject instance world rotation
Parameters
instance (dmGameObject::HInstance) - Gameobject instanceReturns
return (dmGameObject::Quat) - World rotationType: FUNCTION Get game object instance world transform
Parameters
instance (dmGameObject::HInstance) - Gameobject instanceReturns
return (dmGameObject::Vector3) - World scaleType: FUNCTION Get game object instance world transform
Parameters
instance (dmGameObject::HInstance) - Gameobject instanceReturns
return (dmTransform::Transform) - World transformType: FUNCTION Get game object instance uniform scale
Parameters
instance (dmGameObject::HInstance) - Gameobject instanceReturns
return (float) - World uniform scaleType: TYPEDEF Gameobject collection handle
Type: TYPEDEF Opaque handle to component instance
Type: TYPEDEF Opaque handle to internal representation of a component instance
Type: TYPEDEF Opaque handle to a component world
Type: TYPEDEF Gameobject instance handle
Type: TYPEDEF Gameobject properties handle
Type: TYPEDEF Handle to a list of properties (gameobject_props.h)
Type: TYPEDEF Handle to a list of property options
Type: TYPEDEF Gameobject prototype handle
Type: TYPEDEF Collection register.
Type: TYPEDEF Script handle
Type: TYPEDEF Script instance handle
Type: STRUCT Container of input related information.
Type: ENUM Input result enum
Members
INPUT_RESULT_IGNORED - = 0INPUT_RESULT_CONSUMED - = 1INPUT_RESULT_UNKNOWN_ERROR - = -1000Type: TYPEDEF Used for mapping instance ids from a collection definition to newly spawned instances
Type: TYPEDEF Contains property containers for game objects to be spawned
Type: CONSTANT Value for an invalid instance index, this must be the same as defined in gamesys_ddf.proto for Create#index.
Type: FUNCTION Check whether the instance is flagged as a bone.
Parameters
instance (HInstance) - InstanceReturns
result (bool) - True if flagged as a boneType: FUNCTION Create a new gameobject instance
Notes
Parameters
collection (dmGameObject::HCollection) - Gameobject collectionprototype_name (const char*) - Prototype file name. May be 0.Returns
instance (dmGameObject::HInstance) - New gameobject instance. NULL if any error occuredType: ENUM Playback type enum
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
m_ElementIds (dmhash_t) - For composite properties (float arrays), these ids name each elementm_Variant (PropertyVar) - Variant holding the valuem_ValuePtr (float*) - Pointer to the value, only set for mutable values. The actual data type is described by the variant.m_ReadOnly (uint16_t) - Determines whether we are permitted to write to this property.m_ValueType (uint16_t) - Indicates type of the property (of type PropertyValueType).m_ArrayLength (uint16_t) - Number of array entries, if the property is an array and zero otherwise. Max supported length is 2^14 (16384 elements)Type: ENUM Property result.
Members
dmGameObject::PROPERTY_RESULT_OKdmGameObject::PROPERTY_RESULT_NOT_FOUNDdmGameObject::PROPERTY_RESULT_INVALID_FORMATdmGameObject::PROPERTY_RESULT_UNSUPPORTED_TYPEdmGameObject::PROPERTY_RESULT_TYPE_MISMATCHdmGameObject::PROPERTY_RESULT_COMP_NOT_FOUNDdmGameObject::PROPERTY_RESULT_INVALID_INSTANCEdmGameObject::PROPERTY_RESULT_BUFFER_OVERFLOWdmGameObject::PROPERTY_RESULT_UNSUPPORTED_VALUEdmGameObject::PROPERTY_RESULT_UNSUPPORTED_OPERATIONdmGameObject::PROPERTY_RESULT_RESOURCE_NOT_FOUNDdmGameObject::PROPERTY_RESULT_INVALID_INDEXdmGameObject::PROPERTY_RESULT_INVALID_KEYdmGameObject::PROPERTY_RESULT_READ_ONLYType: ENUM Property types.
Members
dmGameObject::PROPERTY_TYPE_NUMBERdmGameObject::PROPERTY_TYPE_HASHdmGameObject::PROPERTY_TYPE_URLdmGameObject::PROPERTY_TYPE_VECTOR3dmGameObject::PROPERTY_TYPE_VECTOR4dmGameObject::PROPERTY_TYPE_QUATdmGameObject::PROPERTY_TYPE_BOOLEANdmGameObject::PROPERTY_TYPE_COUNTType: ENUM Type of property value
Members
dmGameObject::PROP_VALUE_ARRAYdmGameObject::PROP_VALUE_HASHTABLEType: STRUCT Property variant that holds the data for a variable
Members
m_Type (dmGameObject::PropertyType) - property typem_Number (double) - A floating point value (union)m_Hash (dmhash_t) - A hash value (union)m_Url (const uin8_t*) - An URL value (union)m_V4 (float) - A vector4 value (union)m_Bool (bool) - A boolean value (union)Type: ENUM Result enumeration.
Members
dmGameObject::RESULT_OKdmGameObject::RESULT_OUT_OF_RESOURCESdmGameObject::RESULT_ALREADY_REGISTEREDdmGameObject::RESULT_IDENTIFIER_IN_USEdmGameObject::RESULT_IDENTIFIER_ALREADY_SETdmGameObject::RESULT_COMPONENT_NOT_FOUNDdmGameObject::RESULT_MAXIMUM_HIEARCHICAL_DEPTHdmGameObject::RESULT_INVALID_OPERATIONdmGameObject::RESULT_RESOURCE_TYPE_NOT_FOUNDdmGameObject::RESULT_BUFFER_OVERFLOWdmGameObject::RESULT_IDENTIFIER_INVALIDdmGameObject::RESULT_RESOURCE_ERRORdmGameObject::RESULT_CHILD_NOT_FOUNDdmGameObject::RESULT_INVALID_PROPERTIESdmGameObject::RESULT_UNABLE_TO_CREATE_COMPONENTSdmGameObject::RESULT_UNABLE_TO_INIT_INSTANCEdmGameObject::RESULT_UNKNOWN_ERRORType: STRUCT Opaque struct that holds info about the current node
Notes
scene node only exists here, for the purposes of inspecting the scene graph for inspection and testing purposes only.Type: STRUCT Opaque struct that holds info about the current position when traversing the scene
Type: STRUCT Struct that holds info about the current position when traversing the scene
Members
m_NameHash (dmhash_t) - namem_Type (dmGameObject::SceneNodePropertyType) - typem_Value (union) - valuem_Numberm_Hashm_URLm_V4m_Boolm_TextType: STRUCT Holds the property
Members
m_Property (dmGameObject::SceneNodeProperty) - propertyType: ENUM scene node property types
Notes
Members
dmGameObject::SCENE_NODE_PROPERTY_TYPE_NUMBERdmGameObject::SCENE_NODE_PROPERTY_TYPE_HASHdmGameObject::SCENE_NODE_PROPERTY_TYPE_URLdmGameObject::SCENE_NODE_PROPERTY_TYPE_VECTOR3dmGameObject::SCENE_NODE_PROPERTY_TYPE_VECTOR4dmGameObject::SCENE_NODE_PROPERTY_TYPE_QUATdmGameObject::SCENE_NODE_PROPERTY_TYPE_BOOLEANdmGameObject::SCENE_NODE_PROPERTY_TYPE_TEXTdmGameObject::SCENE_NODE_PROPERTY_TYPE_COUNTType: 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
instance (HInstance) - Instancebone (bool) - true if the instance is a boneType: 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
instance (HInstance) - First Instance of the hierarchy to setcomponent_transform (dmTransform::Transform) - the transform for component roottransforms (dmTransform::Transform*) - Array of transforms to set depth-first for the bone instancestransform_count (uint32_t) - Size of the transforms arrayReturns
Number - of instances foundType: FUNCTION Set instance identifier. Must be unique within the collection.
Parameters
collection (dmGameObject::HCollection) - Collectioninstance (dmGameObject::HInstance) - Instanceidentifier (dmhash_t) - IdentifierReturns
result (dmGameObject::Result) - RESULT_OK on successType: FUNCTION Set gameobject instance position
Parameters
instance (dmGameObject::HInstance) - Gameobject instanceposition (dmVMath::Point3) - New PositionType: FUNCTION Sets the value of a boolean property on a component.
Parameters
instance - Instance of the game objectcomponent_id (dmhash_t) - Id of the componentproperty_id (dmhash_t) - Id of the propertyvalue (bool) - Value of the propertyReturns
PROPERTY_RESULT_OK - if the value could be setType: FUNCTION Sets the value of a hash property on a component.
Parameters
instance - Instance of the game objectcomponent_id (dmhash_t) - Id of the componentproperty_id (dmhash_t) - Id of the propertyvalue (dmhash_t) - Value of the propertyReturns
PROPERTY_RESULT_OK - if the value could be setType: FUNCTION Sets the value of a float property on a component.
Parameters
instance - Instance of the game objectcomponent_id (dmhash_t) - Id of the componentproperty_id (dmhash_t) - Id of the propertyvalue (float) - Value of the propertyReturns
PROPERTY_RESULT_OK - if the value could be setType: FUNCTION Sets the value of a matrix4 property on a component.
Parameters
instance - Instance of the game objectcomponent_id (dmhash_t) - Id of the componentproperty_id (dmhash_t) - Id of the propertyvalue (dmVMath::Matrix4) - Value of the propertyReturns
PROPERTY_RESULT_OK - if the value could be setType: FUNCTION Sets the value of a quaternion property on a component.
Parameters
instance - Instance of the game objectcomponent_id (dmhash_t) - Id of the componentproperty_id (dmhash_t) - Id of the propertyvalue (dmVMath::Quat) - Value of the propertyReturns
PROPERTY_RESULT_OK - if the value could be setType: FUNCTION Sets the value of a URL property on a component.
Parameters
instance - Instance of the game objectcomponent_id (dmhash_t) - Id of the componentproperty_id (dmhash_t) - Id of the propertyvalue (dmMessage::URL) - Value of the propertyReturns
PROPERTY_RESULT_OK - if the value could be setType: FUNCTION Sets the value of a vector3 property on a component.
Parameters
instance - Instance of the game objectcomponent_id (dmhash_t) - Id of the componentproperty_id (dmhash_t) - Id of the propertyvalue (dmVMath::vector3) - Value of the propertyReturns
PROPERTY_RESULT_OK - if the value could be setType: FUNCTION Sets the value of a vector4 property on a component.
Parameters
instance - Instance of the game objectcomponent_id (dmhash_t) - Id of the componentproperty_id (dmhash_t) - Id of the propertyvalue (dmVMath::Vector4) - Value of the propertyReturns
PROPERTY_RESULT_OK - if the value could be setType: FUNCTION Set gameobject instance rotation
Parameters
instance (dmGameObject::HInstance) - Gameobject instancerotation (dmVmath::Quat) - New rotationType: FUNCTION Set gameobject instance uniform scale
Parameters
instance (dmGameObject::HInstance) - Gameobject instancescale (float) - New uniform scaleType: FUNCTION Set gameobject instance non-uniform scale
Parameters
instance (dmGameObject::HInstance) - Gameobject instancescale (dmVmath::Vector3) - New non-uniform scaleType: FUNCTION Set gameobject instance x and y scale
Parameters
instance (dmGameObject::HInstance) - Gameobject instancescale_x - New x scalescale_y - New y scaleType: FUNCTION Spawns a new gameobject instance. The actual creation is performed after the update is completed.
Parameters
collection (HCollection) - Gameobject collectionprototype (HPrototype) - Prototypeprototype_name (const char*) - Prototype file name (.goc)id (dmhash_t) - Id of the spawned instanceproperties (HPropertyContainer) - Container with override propertiesposition (dmVMath::Vector3) - Position of the spawed objectrotation (dmVMath::Quat) - Rotation of the spawned objectscale (dmVMath::Vector3) - Scale of the spawned object
return instance HInstance the spawned instance, 0 at failureType: FUNCTION Gets the top node of the whole game (the main collection)
Notes
dmEngine::GetGameObjectRegister(dmExtension::AppParams)Parameters
regist (dmGameObject::HRegister) - the full gameobject registernode (dmGameObject::HRegister) - the node to inspectReturns
result (bool) - True if successfulExamples
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);
}
Type: FUNCTION Get a scene node iterator for the nodes’ children
Parameters
node (dmGameObject::SceneNode*) - the parent nodeReturns
iterator (dmGameObject::SceneNodeIterator) - the iteratorType: FUNCTION Step a scene node iterator to the next sibling
Parameters
it (dmGameObject::SceneNodeIterator*) - the iteratorReturns
result (bool) - true if successful. false if the iterator is finishedType: FUNCTION Create a scene node traversal property iterator
Notes
dmHashReverseSafe64() isn’t available in release builds.Parameters
node (dmGameObject::SceneNode*) - the node to inspectReturns
iterator (dmGameObject::SceneNodePropertyIterator) - the property iteratorExamples
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: ...
...
}
}
Type: FUNCTION Steps the scene node traversal property iterator to the next property
Parameters
it (dmGameObject::SceneNodePropertyIterator*) - the iteratorReturns
finished (bool) - True if the iterator it valid, false if the iterator is finished.Type: STRUCT Update context
Members
m_TimeScale (float) - the scaling factor what was applied on the dt (i.e. the collection update time scale)m_DT (float) - the delta time elapsed since last frame (seconds)m_FixedUpdateFrequency (uint32_t) - Number of of calls per second to the FixedUpdate of each componentType: ENUM Update result enum.
Members
dmGameObject::UPDATE_RESULT_OKdmGameObject::UPDATE_RESULT_UNKNOWN_ERROR