MirrorNetworking / MirrorNetworking/Mirror
SyncVar Hook Call Order on Host
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 870
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
Hooks are invoked in the order the syncvars are defined in the file.
This does not apply for the Host.
On Host hooks are called in the order the corresponding syncvars are set.
On Client everything works as expected.
Technically this is not a problem because of "just set the variables as they are in the file and not random".
This is indeed correct but would not be consistent with the rest of Mirror.
[IMPORTANT] How can we reproduce the issue, step by step:
Open the Basic Example and add a new empty GameObject with the script below attached.
Press 'H' and watch the logs.
public class SyncVarTest : NetworkBehaviour
{
[SyncVar(hook = nameof(Hook1))]
int Y;
[SyncVar(hook = nameof(Hook2))]
int Z;
void Update()
{
if(isHost && Input.GetKeyDown(KeyCode.H))
{
CmdDoSomething();
}
}
[Command]
void CmdDoSomething()
{
Z = Random.Range(100, 500); // On Host this Hook fires first
Y = Random.Range(100, 500);
//Y = Random.Range(100, 500); // Hooks fire in the correct order
//Z = Random.Range(100, 500);
}
void Hook1(int oldValue, int newValue)
{
Debug.LogWarning($"IsHost: {isHost} | Hook1 fired");
}
void Hook2(int oldValue, int newValue)
{
Debug.LogWarning($"IsHost: {isHost} | Hook2 fired");
}
}
Expected behavior
Like the Docs says you would expect that on Host, Hook1 is called first and Hook2 follows.
Screenshots
Desktop:
- OS: Windows | Linux
- Build target: Standalone
- Unity version: 6000.0.29f1 | 2021.3.45f1
- Mirror branch: master[96.0.1] | master[96.10.0]
Additional context
Ignore the first Hook logs after starting as Host because this is another already known Issue.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue in the Basic Example using the provided SyncVarTest script, then compare the host and client hook logs when pressing H. Trace the SyncVar hook dispatch path and verify that host hooks follow declaration order, matching the documented behavior and client behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, unity
- Domain
- game-dev, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 57/100