Marks a field for automatic network synchronization across connected clients.
When a synced field changes, the new value is automatically broadcast to all users in the room.

Primitives (string, number, boolean) sync automatically.
For arrays/objects, reassign to trigger sync: this.myArray = this.myArray

class MyComponent extends Behaviour {
@syncField() playerScore: number = 0;
}
class MyComponent extends Behaviour {
@syncField("onHealthChanged") health: number = 100;

onHealthChanged(newValue: number, oldValue: number) {
console.log(`Health: ${oldValue}${newValue}`);
}
}
class MyComponent extends Behaviour {
@syncField(function(newVal, oldVal) {
// Process incoming value but don't sync our changes
return false;
}) serverControlled: string = "";
}

serializable for editor serialization

  • Parameters

    • onFieldChanged: undefined | null | string | FieldChangedCallbackFn = null

      Optional callback when the field changes (locally or from network).
      Return false to prevent syncing this change to others.

    Returns (target: any, _propertyKey: string | { name: string }) => void