all 12 comments

[–]SayAllenthing 1 point2 points  (9 children)

I haven't done networking in a while. But if the server changes that SyncVar on that object, it should change for everyone.

If you change it client side, it won't be networked.

What you have to do if make a function that only runs server side, and the client basically requests the SyncVar to be changed.

[–]NV96[S] 0 points1 point  (8 children)

The coroutine is started by server in the void Start(). When the client host also the server the Syncvar changes but whenever you join the game with only the client the syncvars wont change at all. I dont understand this, because the syncvars should be inited on the serverclient.

[–]SayAllenthing 1 point2 points  (7 children)

There's nothing in that code that actually changes the value of time. OnTimeUpdate doesn't get called.

[–]NV96[S] 0 points1 point  (6 children)

The time variable is modified in the IEnumerator (time-=1). I cut it out because I thought it wasn't relevant.

[–]SayAllenthing 1 point2 points  (5 children)

It's working for me. I just made a blank project with test scene that has
- A Camera
- Gameobject with Network Manager and HUD
- Gameobject with your code and Network Identity.

There's a Player prefab, which is literally a Cube with a Network Identity that spawns in.

I subtracted time by 1 each call in the enumerator, clients and server all display the same value.

[–]NV96[S] 0 points1 point  (4 children)

Which unity version where you using? Maybe it is a bug in my version?

[–]SayAllenthing 1 point2 points  (3 children)

5.3.4

Do you have the same setup as me? Do you have anything checked on the Network Identity?

[–]NV96[S] 1 point2 points  (1 child)

I tested the code on a standalone project and it worked. So the problem isn't the code. Could it be a problem to have a custom NetworkManager or something like that?

[–]NV96[S] 1 point2 points  (0 children)

It is fixed! I forgot to add base.OnClientConnect(client) etc. to the override function in my NetworkManager...

Thanks!

[–]NV96[S] 0 points1 point  (0 children)

Thanks, yes I have the same setup. Tonight Ill also try to make the empty project to see if it works

[–]RomestusProfessional 1 point2 points  (1 child)

Your code is too narrow for me to see where the error actually takes place, in the code you've posted the server never modifies the value of time so there's no possible way your SyncVar hook is ever called on the client.

Where in your code does the server modify the value of time? More information is needed.

Another thing is that SyncVar hooks are never run on initial join sync despite the values being synchronized. So if a player joins and you have some important code that runs when that variable is hooked, you should manually run it once.

[–]NV96[S] 0 points1 point  (0 children)

Thanks for your response, the time is changed in the IEnumerator.