Object types and parts
An object type describes a kind of thing: which components it has, their values, and
its parts. It lives in objects/<name>.object. Nothing exists in the world until an
object type is placed in a level or spawned by code.
// objects/player.object (from samples/farmhouse)
// The player: a tall box you move with WASD, with a camera attached behind it.
export default object({
mesh: {
mesh: "models/cube.gltf",
texture: "textures/checker.png",
color: vec4(0.3, 0.6, 1, 1),
},
transform: { scale: vec3(0.8, 1.8, 0.8) },
health: { max: 100, current: 45, regen: 3 },
movement: { speed: 4 },
parts: { camera: { type: PlayerCamera, position: vec3(0, 3, 7), rotation: euler(-20, 0, 0) } },
});
Names
The type name is the file name in PascalCase: player_camera.object is PlayerCamera,
grid-node.object would be GridNode. Files in subfolders of objects/ work too; the name
still comes from the file name.
Components
Each key except parts is a component in lowerCamelCase, with an object of field values.
Fields you leave out take the component's default. mesh: "models/x.gltf" is a shorthand
for mesh: { mesh: "models/x.gltf" }.
A type's own transform is applied relative to where an object is placed. A type with
transform: { scale: vec3(0.8, 1.8, 0.8) } placed at vec3(3, 0, 0) ends up at
(3, 0, 0) with that scale.
Parts
A part is another object attached to this one: a camera behind the player, a rotor on a wind turbine, wheels on a car. Parts are the only kind of nesting in Molten, and nesting always means "attached to".
parts: {
camera: { type: PlayerCamera, position: vec3(0, 3, 7), rotation: euler(-20, 0, 0) },
claws: { type: Claws, attach: "hand_r", overrides: { damage: { amount: 12 } } },
}
| Key | Meaning |
|---|---|
type |
Required. The part's object type |
position, rotation, scale |
Placement relative to the owner |
overrides |
Component values for this part only, like a stronger weapon on one enemy |
attach |
A socket name. Recorded, but not used yet (sockets need skeletons) |
At runtime a part is a separate object with the built-in Parent component. Its
Transform is relative to the owner's, and it is destroyed with the owner. Parts may have
parts of their own (up to 8 levels deep).
In Cast, an object type's value has a field per part that holds a nullable handle:
zombie.head is a Handle<ZombieHead> | null.
Object types are Cast types
Every .object file becomes a type you can use in Cast without importing it. A value of
that type has one field per component the file lists (plus transform and handle) and
one per part:
const crate = placedObject("crate-02").as<Crate>()?.get();
if (crate) crate.mesh.color = vec4(1, 0, 0, 1);
Only the components the .object lists are fields. Asking for another
(crate.rigidBody on a type without one) is a compile error:
type Crate has no member 'rigidBody'.
Editing an object type while the game runs
Save the file and every object of that type updates, by this rule: each field takes the new value unless it was changed at runtime. "Changed" is decided by comparing values: a field updates only if it still equals the old default (the type's value plus any level override). Values set from devtools are always kept. See Live reload.