Maybe I’m overthinking this, but I can’t quite wrap my head around how networking works...
The docs mention “Serverside code only works when running local projects” what exactly does that mean?
Context
Trying to learn c#'s syntax and s&box in general so I originally built a simple round controller as its own class all just backend with some print/logs and called it from
GameManager.OnHostInitialize. It worked fine:- start round
- countdown timer
- end round
- run intermission
- start next round
Now I want to replicate the current round and remaining time to clients. I read that
[Sync] is the right way (instead of firing an RPC every second), but it requires making it a Component. That feels odd is this actually the intended use for system-type logic? Should I just make an empty GameObject and attach a component script to handle it?Where I’m stuck
When I test networking by joining from a second instance, the client seems to run its own copy of the script.
They’re not synced, and it looks like the logic is all client-side.
So:
They’re not synced, and it looks like the logic is all client-side.
So:
- Does every client always get its own instance of components?
- How do I make one authoritative “server-side” instance that drives the state?
- Are
[Sync]variables only valid if the object was spawned withNetworkSpawn()? - Is the idea that everything exists on both sides but the host owns and replicates the authoritative version?
TL;DR
I’m confused about:
- what “serverside code only works when running local projects” really means,
- why my component script runs on every client,
- and the correct way to have a single authoritative instance replicate data to all clients via
[Sync].
Any clarification or examples would be appreciated, or if I'm just a retard let me know!