Pick an object of the same scene for an Object variable (#258)
game-maker / gate (push) Successful in 3m32s
game-maker / suite (push) Failing after 10m2s

An Object variable could only be set by a graph while the game runs.
A placed object always showed "(null)", although the other objects of
its scene are there to choose from and the runtime can already find
any object by its id. Now the placed object stores a reference to one
of them, and the running game turns it into the real object.

- Stored as {"$object": "<id>"}. The empty placeholder stays as it
  was, so old projects load unchanged and empty still means "(null)".
- The row of an Object variable on a placed object is a dropdown with
  None and every object of the scene, indented like the Hierarchy.
  The same goes for Object fields in structs and Object items in
  lists, also in the Variables and List tabs.
- The behavior asset keeps "(null)". An asset has no scene, so "Apply
  to asset" is gone from Object rows.
- The runtime resolves the reference when the Variables or Properties
  node reads it. A destroyed target reads as null, a missing one shows
  "(missing)" in the row.
- Inside a container only objects of the same container are offered.
  The reference keeps the template id, so every placement finds its
  own copy.
- Deleting the target clears the reference in the same undo step.
  Paste points references inside the pasted group at the copies and
  leaves outside references alone. Create container and Unpack carry
  references along with the new ids.
- A value a graph writes while running stays in the run. The scene
  keeps the picked object, also in "Run in editor".

Found on the way:

- Setting an override coerced every object slot to empty, in plain
  values, struct fields and list items. The shared objectPlace() now
  keeps the reference.

Not done:

- No eyedropper to pick in the scene, the dropdown is enough for now.
- Deleting a template object in the container editor does not clean up
  references in other scenes. They read as null there.

Tests:

- ./check.sh: 187 files, 2724 tests, CHECK EXIT 0
- e2e 1-9, 51, 57: ALL PASSED, 389 checks
- e2e 1, 57 on the final bundle: ALL PASSED, 17 checks
- 13 unit tests in object-references.test.ts, 5 checks in e2e 57
- Counter-checks: 8 unit breaks fail their tests, the browser break
  without a pick list fails 57b-57d

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 5.5 committed 2026-09-28 14:35:17 +02:00
1 parent e8b3ac0a3b
commit f84defb9b6
24 files changed
+720 -45

No files matched your search

+3 -2
View File
@@ -8,6 +8,7 @@ import {
type PropertyBag,
type PropertyValue,
NO_OBJECT,
objectPlace,
type StructValue,
textOf,
} from '../model/Properties';
@@ -832,7 +833,7 @@ export function coerceValue(def: PropertyDef, value: PropertyValue): PropertyVal
case 'struct':
return structOf(def.fields, value);
case 'object':
return NO_OBJECT;
return objectPlace(value);
default:
return coerceAs(value, def.kind, def.default);
}
@@ -843,7 +844,7 @@ export function coerceValue(def: PropertyDef, value: PropertyValue): PropertyVal
* a struct field is brought into its declared shape, however deep it sits.
*/
export function coerceFieldValue(value: PropertyValue, field: StructFieldDef): FieldValue {
if (field.kind === 'object') return NO_OBJECT;
if (field.kind === 'object') return objectPlace(value);
if (field.kind === 'struct') return structOf(field.fields, value);
return field.kind === 'list' ? listOf(value) : coerceField(value, field.kind);
}
+3 -2
View File
@@ -159,8 +159,9 @@ export const KINDS = [
port: true,
},
/**
* A live object, held for the run only. At rest – in a file, a save, the inspector – it is always
* the empty one, tagged wherever it sits so a run can tell its place from a text (`NO_OBJECT`).
* A live object, held for the run only. At rest – in a file, a save, the inspector – it is the id
* of an object of the same scene (#258) or the empty one, tagged wherever it sits so a run can
* tell its place from a text (`NO_OBJECT`, `objectPlace`).
*/
{
kind: 'object',
+2
View File
@@ -11,6 +11,7 @@ import {
isList,
isStruct,
type ListValue,
objectPlace,
type PropertyValue,
type StructValue,
tagged,
@@ -36,6 +37,7 @@ export function itemKindOf(item: PropertyValue | undefined): NestedKind {
export function makeItem(kind: NestedKind, value: PropertyValue | undefined): ListItem {
if (kind === 'list') return listOf(value);
if (kind === 'struct') return structItemOf(value);
if (kind === 'object') return objectPlace(value);
if (isTaggedKind(kind)) return tagged(kind, coerceField(untag(value), kind));
return coerceField(untag(value), kind);
}