sceneInstantiable.interface
- .metadata206 B
- README.md2.9 KB
- interface.yaml1.4 KB
This package holds more than this page lists. See all of its files in its world.
README.md
sceneInstantiable
Can be placed in a scene. A type that lists sceneInstantiable under
interfaces: in its type.yaml guarantees that instantiate composes any of
its assets under or onto an owning entity, synchronously, and returns the live
root and the map naming what it spawned. A consumer places any such asset with
one call, source:as("sceneInstantiable"):instantiate(target, opts), and it
works for types the consumer has never heard of: the Asset component, a
viewport drop, a procedural generator and a tool argument all place assets this
way.
Implementing it
# marker.assetType/type.yaml
interfaces: [sceneInstantiable]
-- marker.assetType/behavior.luau
local Instantiable = require("@builtin::assetTypes.assetType.shared.instantiable")
local M = {}
M.ref = {
instantiate = function(self, target, opts)
local root = Instantiable.root(self, target, opts)
root.component.add("Text3D", { text = self.name })
return Instantiable.result(self, root, {})
end,
}
return M
A type whose own instantiate means something else meets the member under
M.interfaces.sceneInstantiable.instantiate.
The base inputs
target is the owning entity; with none, the type spawns a fresh root.
opts.position, opts.rotation, opts.scale, opts.name and
opts.temporary mean the same for every type, and Instantiable.root applies
them to a root the type makes (Instantiable.place to one it adopts).
opts.idMap, opts.diff and opts.sourceTag are what the Asset component
passes to every type: a type that spawns no addressable children ignores them.
opts.detached composes a permanent copy that nothing composes again. A type's
own extras (raw, deferred, params) travel in opts beside these, are
always optional, and never change a base input's meaning.
Required behaviour
rootexists on return, with everything composed under it.idMapmaps each original id to the spawned id;{}for none.- Passing the returned
idMapback reproduces the same ids. temporary = truekeeps the root and everything under it out of the saved scene.- Despawning
root, or the composition theAssetcomponent despawns, removes everything the call put in effect.
The conformance suite, sceneInstantiableConformance beside this file, holds
one asset of every implementing type (or of the types a run names) to the base
options' meanings, the returned map reproducing its ids when passed back, and
a detached composition's live root. asset.validate of a world's own type runs
it over that type.
Legacy types
A type that defines M.ref.instantiate and lists nothing (one written
before interfaces: existed, or defined by its behavior.luau alone)
implements sceneInstantiable with a warning (interfaces.implied) naming the
line to add.