Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyncVar OnChange prev value incorrect on clients #800

Closed
maxkratt opened this issue Oct 25, 2024 · 2 comments
Closed

SyncVar OnChange prev value incorrect on clients #800

maxkratt opened this issue Oct 25, 2024 · 2 comments
Labels
Bug Something isn't working Resolved Pending Release

Comments

@maxkratt
Copy link
Contributor

General
Unity version: Unity 6 (6000.0.23f1)
Fish-Networking version: 4.5.2
Discord link: https://discord.com/channels/424284635074134018/1034477094731784302/1299363640188731393

Description
When a SyncVar is changed the OnChange event triggers with the previous value being the same as the next value. This only happens with asServer as false. You may need to create a blank project to replicate this as it was not happening in my old testing project.

Replication
Steps to reproduce the behavior:

  1. Create new project
  2. Import FishNet
  3. Import example package
  4. Open example scene and press play
  5. Press the K key a few times to change the SyncVar
  6. The prev value will print as the same as the next value when asServer is false

Expected behavior
It should be the correct previous value like happens when asServer is true.

Screenshot
Screenshot 2024-10-25 162550

Example Package
SyncVarIssue.zip

@FirstGearGames
Copy link
Owner

FirstGearGames commented Oct 25, 2024

This is intended behavior as clientHost. We moved away from having separate values for clientHost as it was creating more complex code with very little benefit.

You can switch to stable mode to get the old syncVars back but at some point this will become the new default.

@FirstGearGames
Copy link
Owner

As stated above it's normal for 'asServer false' to show the same value when clientHost, in the newest SyncTypes.

ClientOnly seeing the same values however was an error.

The resolution is to go into SyncVar.cs and find this bit...

                if (!base.NetworkManager.IsServerStarted)
                    UpdateValues(nextValue);

                T prev = _value;
                
                InvokeOnChange(prev, nextValue, asServer: false);

Replace with this (moving prev above if check)

                T prev = _value;
                /* If also server do not update value.
                 * Server side has say of the current value. */
                /* Only update value if not server. We do not want
                 * clientHost overwriting servers current with what
                 * they just received.*/
                if (!base.NetworkManager.IsServerStarted)
                    UpdateValues(nextValue);

                InvokeOnChange(prev, nextValue, asServer: false);

Resolved in 4.5.3

FirstGearGames pushed a commit that referenced this issue Oct 29, 2024
- Fixed PreciseTick.Percent value being 0 instead of 1 when checked during a ticked frame.
- Fixed condition where NetworkTransform may not unsubscribe from events on client or server stop.
- Fixed code stripping not working in Unity 2022+ (#798).
- Fixed SyncVar OnChange method having incorrect previous value for clientOnly (#800).
- Fixed foreach enumerator in SyncList (#799).
- Added PreciseTick.GetUnsetValue.
- Fixed preciseTick.Subtract improperly calculating percentages.
- Fixed incorrect parsing of null arrays (#802).
- Added NetworkObject.PreventDespawnOnDisconnect to prevent objects from despawning when the owner disconnects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Resolved Pending Release
Projects
None yet
Development

No branches or pull requests

2 participants