GitHub Documentation Patreon donate button

Local schema mismatch using Unity client



  • Hello.

    I'm trying to use the Unity Client right now. My server has a "GameRoom" which has the following Schema for its state

    export class GameState extends Schema 
    {
      @type([ "int16" ])
      pipes = new ArraySchema<number>();
    }
    

    I then use schema-codegen to generate the following C# class

    public class GameState: Schema
    {
        [Colyseus.Schema.Type(0, "array", "int16")]
        public ArraySchema<short> pipes = new ArraySchema<short>();
    }
    

    When trying to connect to the room using

            client = new Client("ws://localhost:2567");
            try
            {
                room = await client.JoinOrCreate<GameState>("game");
            }
            catch(Exception ex)
            {
                Debug.Log("Exception: " + ex.Message);
            }
    

    I get the error: Exception: Local schema mismatch from server. Use "schema-codegen" to generate up-to-date local definitions.

    I'm not sure if I am doing something wrong or if this is a bug, but I am using schema-codegen to generate the schema class and I am still getting the error. What could be the source of this? Thank you!


  • administrator

    Hi @VanillaDevelop, welcome! 👋

    The Unity client tries to validate all the schema structures locally, based on the "handshake" that comes from the server. What's not very well documented is that, right now, every @type() annotation is going to attach the structures into a "global" context - putting all your room's schemas into the same "global" context, therefore the client will receive schemas from multiple rooms and throw the "mismatch" error in case some of them cannot be found.

    I suggest you create your own @type() to avoid this problem in Unity, as suggested here: https://discuss.colyseus.io/topic/390/schema-handshake-problem-between-server-and-unity-client/2

    I need to provide more documentation about this on the next release that's coming up (0.14)

    Let me know if that works for you



  • This solves the issue. Thank you!


 

GitHub Documentation Patreon donate button

© 2020 Endel Dreyer