class
SceneObject
An object in the scene graph.
It has a transform object that allows it to be positioned, scaled and rotated. It can have other scene objects as children, and will have a scene object as a parent, in which case transform changes to the parent are reflected to the child scene objects (children are relative to the parent).
Each scene object can have one or multiple Components attached to it, where the components inherit the scene object's transform, and receive updates about transform and hierarchy changes.
Public
Methods
~SceneObject
staticCreate
Creates a new SceneObject with the specified name.
Object will be placed in the top of the scene hierarchy.
- name
- Name of the scene object.
- flags
- Optional flags that control object behavior. See SceneObjectFlags.
Destroy
Destroys this object and any of its held components.
- immediate
- If true, the object will be deallocated and become unusable right away. Otherwise the deallocation will be delayed to the end of frame (preferred method).
GetHandle
Returns a handle to this object.
GetPrefabResourceId
Identifies the prefab resource this object is linked to.
Will return an empty ID if the object is not linked to a prefab.
GetPrefabVersion
Returns the version of the prefab the prefab instance was created from.
Not relevant if the object is not a prefab instance.
IsPrefabInstanceRoot
Returns true if this object is linked to a prefab (See IsPrefabInstance()), and is the root of the prefab instance hierarchy (i.e. its parent is either not linked to a prefab, or linked to a different prefab).
GetPrefabInstanceRoot
Returns the root object of the prefab instance that this object belongs to, if any.
Returns null if the object is not a prefab instance.
BreakPrefabLink
Breaks the link between this prefab instance and its prefab.
Object will retain all current values but will no longer be influenced by modifications to its parent prefab, nor will you be able to apply changes from this object to the prefab resource.
HasFlag
Checks if the scene object has a specific bit flag set.
GetTransform
Gets the transform object representing object's position/rotation/scale in world space.
UpdateWorldTransformIfDirty
Updates the world transform if it is dirty.
GetLocalTransform
Gets the transform object representing object's position/rotation/scale relative to its parent.
SetLocalTransform
Sets a new transform for the object, relative to the parent.
SetPosition
Sets the local position of the object.
SetWorldPosition
Sets the world position of the object.
SetRotation
Sets the local rotation of the object.
SetWorldRotation
Sets the world rotation of the object.
SetScale
Sets the local scale of the object.
SetWorldScale
Sets the world scale of the object.
LookAt
Orients the object so it is looking at the provided (world space) where is used for determining the location of the object's Y axis.
GetWorldMatrix
Gets the objects world transform matrix.
GetInvWorldMatrix
Gets the objects inverse world transform matrix.
GetLocalMatrix
Gets the objects local transform matrix.
Move
Moves the object's position by the vector offset provided along world axes.
MoveRelative
Moves the object's position by the vector offset provided along it's own axes (relative to orientation).
SetForward
Rotates the game object so it's forward axis faces the provided direction.
- forwardDir
- The forward direction to face, in world space.
Rotate
Rotate the object around an arbitrary axis.
Rotate
Rotate the object around an arbitrary axis using a Quaternion.
Roll
Rotates around local Z axis.
- angle
- Angle to rotate by.
Yaw
Rotates around Y axis.
- angle
- Angle to rotate by.
Pitch
Rotates around X axis
- angle
- Angle to rotate by.
GetTransformHash
Returns a hash value that changes whenever a scene objects transform gets updated.
It allows you to detect changes with the local or world transforms without directly comparing their values with some older state.
CreateECSEntity
Creates an ECS entity in the provided registry and adds default fragments.
Asserts if entity already exists.
SetParent
Changes the parent of this object.
Also removes the object from the current parent, and assigns it to the new parent.
- parent
- New parent.
- keepWorldTransform
- Determines should the current transform be maintained even after the parent is changed (this means the local transform will be modified accordingly).
GetParent
Gets the parent of this object.
Returns: Parent object, or nullptr if this SceneObject is at root level.
GetChild
Gets a child of this item.
- idx
- The zero based index of the child.
Returns: SceneObject of the child.
IndexOfChild
Find the index of the specified child.
Don't persist this value as it may change whenever you add/remove children.
- child
- The child to look for.
Returns: The zero-based index of the found child, or -1 if no match was found.
GetChildCount
Gets the number of all child scene objects.
IterateHierarchy
Iterates over all the components on this object, and then does the same on all child scene objects recursively.
Calls a callback for each component and scene object.
- onSceneObjectFound
- Called for every child object. If the callback returns false, iteration will stop. If is true, it's also called on the root object itself. May be null.
- onComponentFound
- Called for every component. May be null.
- visitSelf
- If true, will be called for the root object.
GetScene
Returns the scene this object is part of.
Can be null if scene object hasn't been instantiated.
FindPath
Searches the scene object hierarchy to find a child scene object using the provided path.
FindChild
Searches the child objects for an object matching the specified name.
- name
- Name of the object to locate.
- recursive
- If true all descendants of the scene object will be searched, otherwise only immediate children.
Returns: First found scene object, or empty handle if none found.
FindChildren
Searches the child objects for objects matching the specified name.
- name
- Name of the objects to locate.
- recursive
- If true all descendants of the scene object will be searched, otherwise only immediate children.
Returns: All scene objects matching the specified name.
SetActive
Enables or disables this object.
Disabled objects also implicitly disable all their child objects. No components on the disabled object are updated.
GetActive
Returns whether or not an object is active.
- self
- If true, the method will only check if this particular object was activated or deactivated directly via SetActive. If false we we also check if any of the objects parents are inactive.
SetMobility
Determines the mobility of a scene object.
This is used primarily as a performance hint to engine systems. Objects with more restricted mobility will result in higher performance. Some mobility constraints will be enforced by the engine itself, while for others the caller must be sure not to break the promise he made when mobility was set. By default scene object's mobility is unrestricted.
GetMobility
Clone
Makes a deep copy of this object (including all its children).
Cloned object will be parented to the same parent as this object.
AddComponent
Constructs a new component of the specified type id and adds it to the internal component list.
Component must have a parameterless constructor.
GetComponent
Searches for a component with the specified type and returns the first one it finds.
Will also return components derived from the type.
- type
- RTTI information for the type.
Returns: Component if found, nullptr otherwise.
GetComponents
Returns all components on this object.
staticGetRttiStatic
Internal
Methods
SetOwnerCollection
Changes the collection the game object is part of.
Game object will be unregistered with the old collection (if any) and registered with the new collection.
Initialize
Register the scene object and its children with the scene manager, and initialize all of their components.
SetPrefabResourceId
ClearPrefabDelta
Clears the internally stored prefab delta.
If this object is updated from prefab its instance specific changes will be lost.
GetPrefabDelta
Returns a prefab delta object containing instance specific modifications of this object compared to its prefab reference, if any.
SetPrefabDelta
Assigns a new prefab delta.
Caller must ensure the prefab delta was generated for this object.
SetPrefabVersion
SetFlags
Recursively enables the provided set of flags on this object and all children.
UnsetFlags
Recursively disables the provided set of flags on this object and all children.
ClearParent
Sets the current scene parent to null.
Only useful if an object is replacing an existing scene instance root.
Clone
Makes a deep copy of this object (including all its children).
The cloned objects will not be parented to any scene object, not be associated with any scene instance and not initialized.
- cloneOwnerCollection
- Collection into which to place the cloned scene objects. If is true this must be a different collection that the current scene object, otherwise IDs would conflict. The collection's ECS registry will be used for the cloned hierarchy's entities and components.
- preserveIds
- If false, each cloned game object will be assigned a brand new ID. Otherwise the ID of the original game objects will be preserved.
Returns: Cloned scene object hierarchy.
Clone
Makes a deep copy of this object (including all its children).
Cloned object will be parented to the root of the provided scene instance.
- cloneSceneInstance
- Scene instance into which to place the cloned scene objects. If is true this must be a different scene instance that the current scene object, otherwise IDs would conflict.
- initialize
- If false, the cloned hierarchy will just be a memory copy, but will not be present in the scene or otherwise active until Initialize() is called.
- preserveIds
- If false, each cloned game object will be assigned a brand new ID. Otherwise the ID of the original game objects will be preserved.
Returns: Cloned scene object hierarchy.
GetMutableComponents
Returns a modifyable list of all components on this object.
RemoveComponent
Removes the component from the internal component list.
This shouldn't be called externally, use Component::Destroy() instead.
Private
Constructors
SceneObject
Methods
staticCreateInternal
Creates a new SceneObject instance and registers it with the game object collection, and returns a handle to the new object.
- ownerCollection
- Collection to register the scene object with.
- name
- Name of the scene object.
- flags
- Optional flags that control scene object behaviour.
staticCreateInternal
Registers an existing SceneObject instance with the game object collection, and returns a handle to the object.
- ownerCollection
- Collection to register the scene object with.
- sceneObject
- Scene object to register.
DestroyImmediate
Destroys the game object without delay.
Object will be removed from its game object collection, and reference to the object in all active handles will become null. If the object contains any child objects or components, those will be destroyed as well.
QueueForDestroy
Queues the provided game object to be destroyed at the end of the frame.
If the object contains any child objects or components, those will be queued for destroy as well. Object will not be removed from any parent's child or component list.
AddMobilityTag
Adds the ECS mobility tag for the given mobility.
For fresh entities with no existing tags.
IsMovable
Returns true if the scene object can be moved.
This is true if the object has ObjectMobility::Movable mobility.
GetMutableLocalTransform
Returns a mutable reference to the local transform stored in the ECS registry.
GetMutableWorldTransform
Returns a mutable reference to the world transform stored in the ECS registry.
UpdateHierarchyDepthFromParent
Recomputes hierarchy depth based on current parent and propagates to all descendants.
UpdateHierarchyDepthRecursive
Assigns hierarchy depth to this object and descendants, increasing by one per hierarchy level.
NotifyTransformChanged
Notifies components and child scene object that a transform has been changed.
- flags
- Specifies in what way was the transform changed.
UpdateWorldTransform
Updates the world transform.
Reconstructs the local transform matrix and multiplies it with any parent transforms.
SetParentInternal
Internal version of setParent() that allows you to set a null parent.
- parent
- New parent.
- keepWorldTransform
- Determines should the current transform be maintained even after the parent is changed (this means the local transform will be modified accordingly).
SetScene
Changes the owning scene of the scene object and all children.
AddChild
Adds a child to the child array.
This method doesn't check for null or duplicate values.
- object
- New child.
RemoveChild
Removes the child from the object.
- object
- Child to remove.
SetActiveHierarchy
Changes the object active in hierarchy state, and triggers necessary events.
RegisterComponentWithOwnerCollection
Registers the provided component with the owner game object collection and returns the component handle.
InternalAddComponent
Adds the component to the internal component array, and optionally initialized it.
Note the component will only be initialized if this scene object is initialized and
flag is true.
InternalAddComponent
Equivalent to AddComponent(const HComponent & , bool), but internally looks up the component handle from the game object collection.
Fields
mPrefabResourceId
Identifier of the prefab resource that this object is linked to, if any.