Unable to correctly pass classes to match state

I am passing XGame class instance into match state, (state.xgame field). After retrieving XGame instance from state i cannot correctly access XGame.players field. Freshly created XPlayer is a different object from one that return from XGame.players. It can be resolved only by creating a method to return field, like I did with getPlayer() method in XPlayer class:

  1. Versions: Nakama 3.25.0, Docker, Unity SDK
  2. Server Framework Runtime language: TypeScript
class XGame {
  public area: XArea | null = null;
}

class XPlayer {}

class XArea {
  public players: XPlayer[] = [];

  constructor(player1: XPlayer, player2: XPlayer) {
    this.players.push(player1);
    this.players.push(player2);
  }

  public getPlayer = (actorID: number) => {
    return this.players[actorID];
  };
}

export const compareObjects = (
  a: object,
  b: object,
  logger: nkruntime.Logger
) => {
  logger.debug(`OBJECTS ARE ${a === b ? "" : "NOT"} EQUAL`);
};

let player1 = new XPlayer();
let player2 = new XPlayer();
let xgame = state.xgame;
xgame.area = new XArea(player1, player2);
compareObjects(player1, xgame.area.players[0], loopContext.logger); // logs OBJECTS ARE NOT EQUAL
compareObjects(player1, xgame.area.getPlayer(0), loopContext.logger) ;// logs OBJECTS ARE EQUAL
let c = xgame.area.players[0];
let d = xgame.area.players[0];
compareObjects(c, d, loopContext.logger); // logs OBJECTS ARE NOT EQUAL

:tv: Media:

Hello @kinserwe,

There are some limitations around the JS runtime and certain constructs given that the runtime uses Goja, a JS interpreter written in Go, and that there’s some bridging between the server Go code and the JS runtime, sometimes causes some compatibility quirks.

Can you please share your bundled JS code?

Best.