MirrorNetworking / MirrorNetworking/Mirror

Incorrect SyncVar behaviour in host mode

Open
#4,126 1 comment 0 reactions 0 assignees View on GitHub

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
so, after spending a bunch of time debugging

When you host,
when an object spawns in it generates a spawn payload message, however this is immediately when the object is created so only SyncVars that are set in the wake are initialised properly, whilst things that would be post-spawn
e.g

var object =  spawn
object.setup(data)

would be not caught in the initial state,
due to the host mode, processing SpawnMessage, and the associated SyncVars, that means any values that were set post spawn message Serialisation would be set to default value (Since it does all SyncVars),
and then since host mode ignores EntityStateMessage,
that would have the serialised data of what you set it to after spawning it, resulting in the host getting set to an incorrect state

this combines with another issue

Where if you set a SyncVar in host mode, before receiving the spawn message, so in the same frame your spawning it it won't directly trigger hook function

if (NetworkServer.activeHost && !GetSyncVarHookGuard(dirtyBit) && NetworkClient.spawned.ContainsKey(netIdentity.netId))

since it's not yet in NetworkClient.spawned

tested on Commit 0eab9bdf779fa0e5d21bf751a43ab606aec80a5b (latest to commit as of writing)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing host-mode SpawnMessage and EntityStateMessage processing, especially NetworkServer.activeHost, NetworkClient.spawned, and the GetSyncVarHookGuard condition. Reproduce the described spawn-then-setup sequence and same-frame SyncVar assignment; done means host state retains post-spawn values and the expected hooks run.

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
Active
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.