Skip to content

Expressions: add $parent binding paths - #804

Open
pgilfernandez wants to merge 1 commit into
friction2d:mainfrom
pgilfernandez:parents-in-expressions-v1
Open

Expressions: add $parent binding paths#804
pgilfernandez wants to merge 1 commit into
friction2d:mainfrom
pgilfernandez:parents-in-expressions-v1

Conversation

@pgilfernandez

@pgilfernandez pgilfernandez commented Aug 6, 2026

Copy link
Copy Markdown

As requested here, this PR adds a symbolic $parent path prefix to Friction expression bindings.

Expressions can now access properties from an object's transform parent without referencing that object by name.

Usage

Access the direct parent's translation:

// Bindings
parentX = $parent.transform.translation.x;

// Calculate
return parentX;

Access a grandparent by chaining $parent:

// Bindings
grandParentRotation = $parent.$parent.transform.rotation;

// Calculate
return grandParentRotation;

Any number of parent levels can be requested:

$parent
$parent.$parent
$parent.$parent.$parent

$parent must appear at the beginning of a property path.

Parent resolution

$parent follows Friction's actual transform-parent relationship, rather than only the visual containment hierarchy.

This means it supports:

  • The default transform inherited from the containing group.
  • Explicit parenting to another object.
  • Multiple parent levels through $parent.$parent.
  • Reparenting after the expression has already been created.

If the requested parent does not exist, the binding is marked as invalid.

Dynamic rebinding

Bindings beginning with $parent remain symbolic instead of being converted into object-name paths.

When an object's transform parent changes, Friction emits a logical path update and resolves the binding again. Expressions therefore follow the new parent automatically without needing to be reopened or edited.

Dependency handling

Existing expression dependency and cycle validation remains active.

A binding through $parent is treated like any other property binding, so circular expression dependencies are rejected.

Editor integration

The expression editor now provides:

  • $parent syntax highlighting.
  • $parent autocomplete.
  • Property completion after $parent.
  • Property completion through chained parent paths.

For example:

$parent.transform.translation.x
$parent.$parent.transform.rotation

Serialization

No EV or XEV format changes are required.

$parent paths are stored inside the existing expression binding string and resolved when the expression is loaded.

Validation

Test builds:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant