Schema mismatch server-unity

Hey! I'm stucking on this problem, don't know what's wrong please help

Server-side:
import { ArraySchema, Schema, type } from "@colyseus/schema";

export class Profile extends Schema {
@type("string")
uid: string = '';

@type("string")
nickname: string = '';

@type("number")
avatar: number = 0;

@type("number")
score: number = 0;

@type("number")
exp: number = 0;

@type("number")
level: number = 0;

};

export class Gamer extends Schema {

/// BUG !!!

@type(Profile)
profile: Profile = new Profile();

@type(["number"])
cards = new ArraySchema<number>();

@type("number")
coins: number = 0;

@type("number")
chips: number = 0;

@type("number")
prize: number = 0;

@type("number")
seat: number = -1;

};

client-side:

using Colyseus.Schema;

namespace Poker.Entities {

/// <summary>
/// Represent gamer datas other gamers could see
/// </summary>


public class Profile : Schema {
    
    [Type(0, "string")]
    public string uid = default(string);
    
    [Type(1, "string")]
    public string nickname = default(string);

    [Type(2, "number")]
    public float avatar = default(float);

    [Type(3, "number")]
    public float score  = default(float);

    [Type(4, "number")]
    public float exp  = default(float);

    [Type(5, "number")]
    public float level  = default(float);
    
}


/// <summary>
/// Instance of user in holdem game
/// </summary>
public class Gamer : Schema
{
    [Type(0, "Profile", typeof(Profile))]
    public Profile profile = new Profile();
    
    [Type(1, "array", typeof(ArraySchema<float>))]
    public ArraySchema<float> cards = new ArraySchema<float>();
    
    [Type(2, "number")]
    public float coins  = default(float);

    [Type(3, "number")]
    public float chips  = default(float);

    [Type(4, "number")]
    public float prize  = default(float);

    [Type(5, "number")]
    public float seat  = default(float);
    

}

}

I believe the problem comes from Profile but don't know how to solve that. Thanks.

Hi @niaina,

I'm sorry you're getting this, there is an explanation and how to fix this here: https://github.com/colyseus/colyseus-unity3d/issues/131

This usually happens when you have multiple state/room definitions and use the global type imported from @colyseus/schema. We'd like to fix this on a next version to display warnings instead of throwing errors when this happens!

Let me know if the solution described on GitHub works for you! Cheers!

Tried but unfortunately the problem persists

Hi @niaina, I see you posted here that you're still getting this error :(

Can you share your schemas/room structures you have on the server? There are two things you could try that will potentially fix this:

  • Remove any unnecessary room/schema structures that you are not using
  • Use const type = Context.create(), and use the same type reference for annotating your schema classes.

Looking forward to hear from you!

@niaina perhaps you're also facing what has been just documented here? https://github.com/colyseus/colyseus-unity3d/issues/131#issuecomment-814308572

Finally, got i worked. The problem was in the child schema type. I have two schemas A and B. B contains A. I used the wrong type anotation :
[Type(0, "A", typeof(A))]
public A a = new A();

Should be
[Type(0, "ref", typeof(A))]
public A a = new A();