SceneObject
Lens Studio v1.0.0+
Scripting Name: SceneObject
Inherits from SerializableWithUID
Description
An object in the scene hierarchy, containing a Transform and possibly Components. A script can access the SceneObject holding it through the method script.getSceneObject()
.
Methods
copyComponent(Component component)
: Component
Copies component
and adds it to the SceneObject, then returns it.
copySceneObject(SceneObject sceneObject)
: SceneObject
Creates a shallow copy of the passed in sceneObject
(not including its hierarchy), and parents it to this SceneObject.
copyWholeHierarchy(SceneObject sceneObject)
: SceneObject
Creates a deep copy of the passed in sceneObject
(including its hierarchy), and parents it to this SceneObject.
createComponent(String typeName)
: Component
Adds a new component of type typeName
to the SceneObject.
destroy()
: void
Destroys the SceneObject.
getChild(Number index)
: SceneObject
Returns this SceneObject’s child at index index
.
getChildrenCount()
: Number
Returns the number of children the SceneObject has.
getComponent(String componentType)
: Component
Returns the first attached Component with type matching or deriving from componentType
.
getComponents(String componentType)
: Component
[]
Returns a list of attached components with types matching or deriving from componentType
.
getParent()
: SceneObject
Returns the SceneObject’s parent in the hierarchy, or null if there isn’t one.
getTransform()
: Transform
Returns the Transform attached to the SceneObject.
hasParent()
: Boolean
Returns whether the SceneObject has a parent in the scene hierarchy.
removeParent()
: void
Unparents the SceneObject in the hierarchy, making it an orphan.
setParent(SceneObject newParent)
: void
Sets the SceneObject’s parent to newParent
in the scene hierarchy.
setParentPreserveWorldTransform(SceneObject newParent)
: void
Changes the parent of the SceneObject without altering its world position, rotation, or scale.
Properties
enabled
: Boolean
Whether the SceneObject, including its components and children, is enabled or disabled.
layer
: LayerSet
Gets or sets the LayerSet of layers this SceneObject belongs to. This is used to determine which Cameras will render the SceneObject.
name
: String
The name of the SceneObject.
Inherited Methods
isSame(SerializableWithUID other)
: Boolean
Returns true if this object is the same as other
. Useful for checking if two references point to the same thing.
getTypeName()
: String
Returns the name of this object’s type.
isOfType(String type)
: Boolean
Returns true if the object matches or derives from the passed in type.
Examples
// Look for a MaterialMeshVisual on this SceneObject
var sceneObj = script.getSceneObject();
var meshVisual = sceneObj.getComponent("Component.MaterialMeshVisual");
if(meshVisual)
{
// ...
}
// Rename each child SceneObject
var sceneObj = script.getSceneObject();
for(var i=0; i<sceneObj.getChildrenCount(); i++)
{
var child = sceneObj.getChild(i);
var newName = i + "_" + child.name;
child.name = newName;
print(child.name);
}
Still Looking for help?
Visit Support