question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Local schema mismatch from server" - when defining multiple rooms/states

See original GitHub issue

This error is reported often, and one of its causes is when multiple room/state classes are defined in the server with the same schema “context”.

Internally, every @type() call is going to register the property in a “global” context:

import { type, Schema } from "@colyseus/schema";

class State1 extends Schema {
  @type(...) my_prop
}

class State2 extends Schema {
  @type(...) my_prop
}

To avoid registering every schema in the global context, you can create a different context like this:

import { Context, Schema } from "@colyseus/schema"; // do not import "type" here

const type = Context.create(); // this is your @type() decorator bound to a context

class State2 extends Schema {
  @type(...) my_prop
}

Actions needed:

  • Update documentation to encourage creating different contexts, especially in Unity because of the crash
  • Throw WARNING on the client-side instead of ERROR when handshake sends more structures than necessary

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
endelcommented, Dec 16, 2020

Hi @sorrow31812, for plain JavaScript it is a bit complicated, the general suggestion is to always use TypeScript:

// javascript
const schema = require("@colyseus/schema");

// create a new context
const context = new schema.Context();

class MyState extends schema.Schema {
}
schema.defineTypes(MyState, {
  currentTurn: "string"
}, context); // use the context

Make sure you use the specified context for every structure your state depends on, otherwise the “schema mismatch” is going to happen

0reactions
hdev72commented, Jun 21, 2022

hello dear friends i have this error only in android build of unity (apk), in editor when i running game every thing is ok

Read more comments on GitHub >

github_iconTop Results From Across the Web

Local schema mismatch using Unity client
I get the error: Exception: Local schema mismatch from server. Use "schema-codegen" to generate up-to-date local definitions.
Read more >
(Schema mismatch) error message occurs when you try to ...
In the File name box, type Ntds_logging, and then click OK. Typically, the administrator's Desktop folder is C:\Documents and Settings\ ...
Read more >
Schema mismatch: Property X in class Y is nullable on one ...
In my app, Folders can have many, and belong to many Folders . I'm not sure what this error means by “nullable on...
Read more >
template mismatches from local to cloud development
I am getting a Schema Mismatch error when transferring Content from the queue. I double checked to make sure the names and aliases...
Read more >
Diplomarbeit
The practical part of this thesis is a proto- type implementation of the system encompassing a backend server infrastructure, portable terminal clients bound...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found