First and foremost: while I have some experience with the Unity engine, I am an absolute beginner when it comes to Networking (concepts-wise and in practice), so I do apologize for any vagueness or confusion on my part. Also, it means that i’m approaching the topic from a high-level POV, as anything below the HLAPI is currently inaccessible to me.
When I attach a script to a GameObject, then spawn that gameobject across the network, is that script’s code running on the server, the clients, or both of them? How many instances of that script exist and where?
I realize that this sounds like the answer would be “RTFM”, but the documentation doesn’t talk about this and often assumes that knowing the answer to this is a given, and while I did some tests, even when I make something work the way i want it to, I can’t understand why it does, so I thought i’d be wise to pose the question directly.
By reading the documentation and tinkering on my own, I know that:
- there are ways to make portions of the code run only on the server or clients (ClientRPCs,Command functions, etc). to be clear, my question refers to “ordinary” code, or code that would run the same even when not using the UnityEngine.Networking namespace.
- UNet’s architecture implies that, unless specified otherwise (with the “hasLocalAuthority” flag or in the case of playerObject),the server has authority on any network object.
I’m trying to implement multiplayer functionality in a RTS game, and from what I understood so far, the best way to go about it would be to make it so that a good slice of gameplay stuff (such as units tracking, resources tracking, and generally anything that involves the status of the game) should be handled on the server and then trickle down to the client, while handling all the rest locally (all the aesthetical stuff like animations and sounds, UI, and generally all non-gameplay-related code). This means that, code-wise, there should be a strong separation between stuff that is ran only on the server and the rest, but I can’t do that if I don’t understand the basics of UNet first.
It seems useless to provide code snippets since this is not a specific case but a general doubt.
I apologize if this sounds confusing or vague, but i can’t figure it out on my own for the life of me.
Thanks, and cheers!