Banter GameObjects, Transforms, and Hierarchies
BS.GameObject is the container used to place content in a Banter scene. Its Transform controls position, rotation, and scale, while components provide rendering, physics, audio, media, UI, interaction, and synchronization.
Create a clearly named object, give it an initial local transform, place it in a hierarchy, and add only the components required for its role.
- Create the GameObject with a name and optional transform, layer, tag, or parent.
- Add visual, physical, audio, media, UI, or interaction components.
- Keep the returned object and component references for later updates and cleanup.
Create a GameObject
The name is the required constructor field. The current API also accepts an ID, layer, active state, tag, local transform, and parent:
const parent = new BS.GameObject({
name: "Exhibit"
});
const display = new BS.GameObject({
name: "Display",
localPosition: new BS.Vector3(0, 1.2, 0),
localEulerAngles: new BS.Vector3(0, 45, 0),
localScale: new BS.Vector3(1, 1, 1),
active: true,
layer: 0,
tag: "Interactive",
parent
});
The local transform is relative to the parent. An object without a parent sits at the root of the scene hierarchy.
World and Local Transforms
Banter provides separate methods for world-space and parent-relative values:
| Goal | Method |
|---|---|
| Set world position | SetPosition() |
| Set local position | SetLocalPosition() |
| Set world Euler rotation | SetEulerAngles() |
| Set local Euler rotation | SetLocalEulerAngles() |
| Set world quaternion rotation | SetRotation() |
| Set local quaternion rotation | SetLocalRotation() |
| Set local scale | SetLocalScale() |
display.SetPosition(new BS.Vector3(2, 1, 4));
display.SetLocalEulerAngles(new BS.Vector3(0, 90, 0));
display.SetLocalScale(new BS.Vector3(1.5, 1.5, 1.5));
Use local methods when the object should stay arranged relative to its parent. Use world methods when the final scene location matters regardless of the hierarchy.
Watch Transform Changes
WatchTransform() monitors selected transform properties:
display.WatchTransform(
[BS.PN.position, BS.PN.rotation],
(transform) => {
console.log(transform.position);
console.log(transform.rotation);
}
);
Use property constants from BS.PN so the watched values match the official API.
Build and Search Hierarchies
SetParent() changes the parent and accepts a worldPositionStays value:
display.SetParent(parent, true);
The API can find a direct or nested child by name or path:
const child = parent.Find("Display");
const nested = parent.Find("Display/Label");
Traverse() walks through children recursively. The documented second argument changes traversal between descendants and ancestors.
Add and Find Components
const material = display.AddComponent(
new BS.BanterMaterial({
color: new BS.Vector4(1, 1, 1, 1)
})
);
const transform = display.GetComponent(BS.CT.Transform);
AddComponent() returns the added component. GetComponent() accepts a component type such as a value from BS.CT.
Tags, Layers, Activity, and Bounds
The GameObject API provides methods for names, tags, layers, network IDs, and active state:
display.SetTag("Pickup");
display.SetLayer(3);
display.SetActive(true);
display.SetNetworkId("display-001");
GetBounds(true) returns collider bounds. Passing true requests bounds based on colliders.
GameObject Events
GameObjects can emit click, grab, drop, collision, trigger, raycast intersection, browser-message, and object-update events. Collision and trigger events require the documented collider event setup.
display.On("click", (event) => {
console.log(event.detail.point);
console.log(event.detail.normal);
});
Destroy Runtime Objects
Call Destroy() when a temporary GameObject is no longer required:
display.Destroy();
Remove references and event logic associated with destroyed runtime objects so later code does not continue trying to use them.
Common Questions
Why does my Banter child object move when its parent moves?
A child's local transform is relative to its parent. Use the world-space transform methods when you need to place it at a particular scene position.
Why does Find return no nested GameObject?
Check the exact object names and hierarchy path. Nested lookup uses a path such as Parent/Child relative to the GameObject on which Find() is called.
Official References
Related Navigation
- Banter JavaScript SDK Basics
- Banter Rendering and Geometry
- Banter Physics and Grabbable Objects
- Banter VR Documentation