Spawn node: place assets at runtime into the play copy, Spawner demo behavior
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
c3a533c4e5
commit
91ee2feadd
13 files changed
+219
-37
No files matched your search
@@ -62,6 +62,12 @@ export interface NodeContext {
|
||||
*/
|
||||
moveAndSlide(target: EntityHandle, dx: number, dy: number): { blockedX: boolean; blockedY: boolean };
|
||||
log(message: string): void;
|
||||
/**
|
||||
* Places a new instance of an asset into the running scene and returns it. The position is
|
||||
* local to `parent` (world when none). Returns null when the asset does not exist or cannot
|
||||
* be placed (a scene). Spawned behaviors run their `On start` on the next tick.
|
||||
*/
|
||||
spawn(assetId: string, position: { x: number; y: number; z: number }, parent: EntityHandle | null): EntityHandle | null;
|
||||
destroy(target: EntityHandle): void;
|
||||
stop(): void;
|
||||
}
|
||||
|
||||
@@ -346,6 +346,22 @@ registerNode({
|
||||
return { next: 'exec' };
|
||||
},
|
||||
});
|
||||
registerNode({
|
||||
type: 'Spawn',
|
||||
label: 'Spawn',
|
||||
category: 'action',
|
||||
description: 'Creates a new instance of an asset in the running scene at (x, y, z) – local to the parent when one is connected, world coordinates otherwise. Outputs the new object.',
|
||||
inputs: [exec(), num('x'), num('y'), num('z'), obj('parent')],
|
||||
outputs: [exec(), obj('object')],
|
||||
// Placeholder options: the graph inspector lists the project's placeable assets.
|
||||
params: [{ key: 'asset', label: 'Asset', kind: 'enum', default: '', options: [] }],
|
||||
run: (ctx, i, p) => {
|
||||
const assetId = String(p.asset ?? '');
|
||||
const spawned = assetId ? ctx.spawn(assetId, { x: asNumber(i.x), y: asNumber(i.y), z: asNumber(i.z) }, asEntity(i.parent)) : null;
|
||||
if (!spawned) ctx.log(assetId ? `Spawn: asset ${assetId} not found` : 'Spawn: no asset selected');
|
||||
return { outputs: { object: spawned }, next: 'exec' };
|
||||
},
|
||||
});
|
||||
registerNode({
|
||||
type: 'Log',
|
||||
label: 'Log',
|
||||
|
||||
Reference in new issue
Block a user