colyseus / colyseus-unity-sdk

⚔ Colyseus Multiplayer SDK for Unity
https://docs.colyseus.io/getting-started/unity-sdk/
MIT License
371 stars 100 forks source link

OnStateChange Called When Current Value And Previous Values are same #217

Open TarunPhonato opened 1 year ago

TarunPhonato commented 1 year ago

When Current Value And Previous Values are same why I received OnState Change callback on same time.

It's working fine while playing on Unity Editor. Unity version : 2020.2.2f1 Colyseus SDK version : 0.15.4

Untitled

endel commented 1 year ago

Hi @TarunPhonato, could you please provide a small project that reproduces this issue? (with code for both server and client)

TarunPhonato commented 1 year ago

Hello Endel,

I have attached a small project that reproduces this issue (with code for both server and client). Please look into it.

- Issue Points :- -When Current Value And Previous Values are the same, why did I receive OnStateChange callback at the same time ( LGameManager. PawnOnStepsMovedChange) -When resetting value of stepsMoved to -1 after reaching to 57 the change is not getting triggered on client side

Client Side :- Unity version: 2020.2.2f1 Colyseus SDK version : 0.15.4

endel commented 12 months ago

Hi @TarunPhonato, thanks for the reproduction scenario.

I can confirm the misbehavior - they're 2 known-issues from the state sync structures (aka schemas):

1) The re-triggering of events, even if currentValue and previousValue are the same

This is due to the usage of experimental filters. I'd suggest treating this edge case on your end. (There are plans on replacing the current filter/filterChildren implementation with a different solution - filters are going to be slowly deprecated in the future)

2) The callback is not being triggered on the client-side

This can happen when the same schema instance is being re-used in many places within the state. I've just created an issue describing the problem here.. One easy way to fix this, is by calling instance.clone() instead of sharing the same instance.

This issue does not happen when cloning the instances, only when sharing the same instance - which will result in the instance being shared on the client-side as well.


I see you work for Phonato Studios, it would be great if you can convince them to sponsor the project, if the company is benefiting from Colyseus 🙏

Cheers, I hope this helps, and let me know if you have any other questions

TarunPhonato commented 11 months ago

Thanks for the Help!

Actually we are starting a new project. I will talk to management regarding sponsors.

On Tue, Aug 22, 2023 at 7:16 AM Endel Dreyer @.***> wrote:

Hi @TarunPhonato https://github.com/TarunPhonato, thanks for the reproduction scenario.

I can confirm the misbehavior - they're 2 known-issues from the state sync structures (aka schemas): 1) The re-triggering of events, even if currentValue and previousValue are the same

This is due to the usage of experimental filters. I'd suggest treating this edge case on your end. (There are plans on replacing the current filter/filterChildren implementation with a different solution https://github.com/colyseus/colyseus/wiki/Public-Roadmap#colyseus-framework

  • filters are going to be slowly deprecated in the future) 2) The callback is not being triggered on the client-side

This can happen when the same schema instance is being re-used in many places within the state. I've just created an issue describing the problem here. https://github.com/colyseus/schema/issues/151. One easy way to fix this, is by calling instance.clone() instead of sharing the same instance.

This issue does not happen when cloning the instances, only when sharing the same instance - which will result in the instance being shared on the client-side as well.

I see you work for Phonato Studios, it would be great if you can convince them to sponsor the project, if the company is benefiting from Colyseus 🙏

Cheers, I hope this helps, and let me know if you have any other questions

— Reply to this email directly, view it on GitHub https://github.com/colyseus/colyseus-unity-sdk/issues/217#issuecomment-1687289488, or unsubscribe https://github.com/notifications/unsubscribe-auth/BAFSD4BDGGLHYPSPYXOE6QDXWQFNRANCNFSM6AAAAAA3T6MBWM . You are receiving this because you were mentioned.Message ID: @.***>

-- Regards Tarun Kumar