-
Not sure where to ask or create issue on this one. I have problem with some schemas using inheritance. I debugged this for awhile and found out that on C# SDK i receive this fields As you can see there are few repeating ones as i assume from inheritance. By field names I found what scheme it was. @entity
export class Enemy extends EntityLiving {
@type('string')
targetPlayer: string = undefined;
agroDistnace: number;
lastDistanceToTarget: number = 0;
constructor(type: EntityType, agroDistance: number, attributes: Attributes) {
super(attributes);
this.type = type;
this.agroDistnace = agroDistance;
}
... other functions
}
@entity
export abstract class EntityLiving extends UpdatebleEntity implements ILiving {
@type(Attributes)
attributes: Attributes;
constructor(attributes: Attributes) {
super();
this.attributes = attributes;
}
}
@entity
export abstract class UpdatebleEntity extends Entity implements IUpdate {
shouldBeRemoved = false;
abstract shouldUpdate(world: GameWorldState): boolean;
onUpdate(_world: GameWorldState) {}
}
@entity
export abstract class Entity extends Schema {
@type(Vector2D)
position: Vector2D;
@type('string')
uuid: UUID;
@type('string')
type: EntityType = EntityType.GENERIC;
constructor() {
super();
this.uuid = randomUUID();
this.position = Vector2D.ZERO.clone();
}
abstract onSpawn(world: GameWorld): void;
abstract onDespawn(world: GameWorld): void;
} So for some reason receiving fields does not represent any type and it result in null in C# sdk and will print out schema mismatch https://github.com/colyseus/colyseus-unity-sdk/blob/master/Assets/Colyseus/Runtime/Colyseus/Serializer/SchemaSerializer.cs#L80 All this happening at handshake moment and no state is updated, it only initialized as room been created I tried checking generated classes from schema-codegen and they are matching in inherited types, name and order of fields I'm kinda out of ideas what is i'm doing wrong here... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
Hi @AymanDev 👋 I hope you are well! The The Unity SDK needs to assign the types to their respective class definitions before decoding, and I'm afraid the We don't have tests for this specific scenario... Could you please share a minimal way to reproduce this issue so I can investigate? Thank you! |
Beta Was this translation helpful? Give feedback.
Hi @AymanDev, let me try to explain what happened. Hopefully these changes fix the issue for you.
The following changes were made:
state.property1.property2
), so it's required to.Listen()
for.property1
to be available first - Please check this PR at AymanDev/colyseus-inheritance-issue#1@colyseus/schema
fixed the Reflection encode order - some types were exposed before their Parent/base type was available, causing issue at decoding time on C# (colyseus/schema@273baf9)handshake
colyseus/colyseus-un…