GitHub Documentation

Nestesd states not updated on client (no listen event triggered)

  • Hi,

    I dont understand how nested states needs to be changed on server side to trigger the listen event on client side.
    I would like to use following classes as custom states.


    onInit() {
       this.state.setState(new GameState());


    export class GameState {
      players: EntityMap<PlayerState> = {};


    export class PlayerState {
      tilePosX: number = 0;
      tilePosY: number = 0;
      isNpc: boolean = false;
      moveDirState: MoveDirState = MoveDirState.NONE();


    export class MoveDirState {
      moveDir: MOVE_DIR = MOVE_DIR.NONE;
      time: number = 0;

    Problem is that any change to PlayerState.moveDirState does not trigger listen events on client. Even that moveDirState is initially send to client

    // Initial update with moveDirState as attribute
    { operation: "add",  attribute: "moveDirState" , value: { moveDir: 4, time: 0} ... }

    any update on serverside (this is a player instance)

    // Not working tries
    // 1 Not working helper to set values inside the class
    // this.moveDirState.set(moveDir, time);
    // 2 Not working set attributes from player class
    this.moveDirState.moveDir = moveDir;
    this.moveDirState.time = time;
    // 3 Not working creating new instance
    this.moveDirState = new MoveDirState(moveDir, time);
    // Just to check if update working, this is working
    this.tilePosX -= 1;

    Listener on client side looks like this.
"players/:id/:attribute", (change: DataChange) => {
       console.log("Update state for " +, change);

    Thank you very much

  • administrator

    Hi @trenrod, welcome!

    When listening for changes, you usually need to provide the full path of the variable you're interested in.

    In your example ("players/:id/:attribute"), it will listen for additions and removals of the whole moveDirState reference, and not it's children.

    To get more data from the moveDirState variable, you can listen for it like this:"players/:id/moveDirState/:prop", (change: DataChange) => {
       console.log("Player " +, " update on moveDirState:", change.path.prop, "changed to", change.value);

    Hope this helps! Cheers!


© 2021 Lucid Sight, Inc