Hi,
I’ve made a multiplayer game that can be played locally with game controllers and mouse and keyboard and now I’m turning it into multiplayer with UNET but the more I read the documentation, the more confused I become.
There are several main components of the game and would appreciate if someone would give me big picture on transforming these parts into multiplayer:
-
There are several maps that player can play with so the NetworkManager with only one “online” map won’t work.
-
Bullets. I’m not sure how to shoot bullets on the network. Use Network Transform? Network Identity seems to be required. Server Authority? God.
-
There is a game manager that determines when to finish the game or how to act on different sections of the game based on the game mode player is on, how should I put it in network?
-
There are collectible items in the game that get spawned on different locations. How I can do this?
I rather not use Unity’s network spawn prefab (forgot it’s name).
-
There are chests that get spawned on the map and chest spawn manager that determines what to spawn open they getting opened.
I rather to code most of the things and avoid using premade prefabs to maximum control.
Cheers.
-
There are methods for the server to change the scene on all clients: http://docs.unity3d.com/ScriptReference/Networking.NetworkManager.ServerChangeScene.html
-
It’s probably bad networking design to spawn bullets over the network. Maybe think about sending over the network where the bullet is spawned from, and let all the bullet code be executed by each client individually - and then only have the server determine what the bullet actually damages.
-
This seems like a script with an update that should only run on the server. It would change the scene (just like my answer to your first question) whenever you want. Right? If you derive a script from NetworkBehaviour instead of MonoBehaviour, you can use the isServer boolean to check whether you are on the server, and only do your checks inside there. Like:
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
public class GameManager : NetworkBehaviour
{
void Start ()
{
}
void Update ()
{
if(isServer)
{
//do checks to see whether to finish the game / change scene, etc.
}
}
}
-
Everything you want to synchronise over the network should be a prefab and in your case registered through the networkmanager. However, if you just want to spawn the objects locally, you can also just call a function from the server to all clients to spawn an object somewhere, and leave the clients to figure things out themselves. However, as UNET tries to enforce a server authoritative model, this could easily lead to desynchronisations and will eventually lead to a giant mess! So… maybe think about that a bit more, try to use the prefab system, and then decide. Try first 
-
Same as above.
Thank you so much for your reply.
-
Thanks.
-
I thought about the same thing as well but how and whom determines authority of what bullet says it hits? In other words when a bullet hits a wall, will a code on server should run for it to bounce/ricochet? What if it hits a player, how we can sure it’s authenticity?
-
Thanks
-
So here is one of places that gets me confused. To have a, say a bullet, spawn on the network there are different things to do which I’m not sure how relate to each other:
A) You have to drag and drop the bullet prefab to Network Manager
B) I have to issue a command to instantiate and spawn
C) I have to call Spawn to have it actually appear on other clients
D) I have to have SyncVar probably?
Do these steps overlap somewhay? What each of those steps do behind the scene?
-
Thanks but I’m still lost here, see my answer to 4. I know the server should spawn chests and also server should know what to instantiate. So I have to add 20 different things to NetworkManager since chest spawner may spawn any of those?
-
Do you think I should use Transport Layer for things I want to use? I’m a bit afraid of it since it’s low level but I think provides best control rather than inheriting all these prefabs and scripts and trying to work it out.
- This is where networking can get really tricky and where you have to ‘design’ your own system and solutions! I’m by no means an expert on this topic, but what I have been doing so far (and it’s not nice, but it works…) is sending over input to all clients and running the gameplay code everywhere locally, synchronising when possible. (For instance, I send over that I clicked to fire a bullet everywhere, but each player locally fires the not-networked bullet.) However, as the server is authoritative, it could sometimes be the case that because of the slight difference between the server and the clients in time and synchronisation, something might just happen on the client that doesn’t ‘just’ happen on the server. In my particular case, this is okay, and that makes everything waaaay easier in terms of networking code.
However, if you want to solve this problem for your game, you may be looking at interpolating or extrapolating data or input, predicting and synchronisation. But I know nothing about that 
- If you want to spawn an object that should be synchronised over the network (that means: either the transform needs to be synchronised, or it has scripts that need to send ClientRpc’s, or something else needs to be networked), it must be registered either through the NetworkManager or ClientScene.RegisterPrefab(), and spawned on the server using NetworkServer.Spawn(). A command is only needed if you want to make this spawn happen from a non-server client, to tell the server to spawn something, and a syncvar is only needed if you want to synchronise a variable on a script… but those last two things are not mandatory to spawn an object

But let me repeat that, often, you’ll only need to tell clients that they need something in their local game, non-networked, which can simply require a ClientRpc method that tells each clients where to instantiate what.
5 and 6. I suggest thinking about which things need to be synchronised over the network and which don’t. For instance, I can imagine that a prefab of a chest, registered with the NetworkManager, can be spawned over the network, while an attached script decides what content to give it locally. So, you won’t need to make a hundred prefabs - you just need to make a structure that allows you to do some things locally and some things over the network. See what I mean? NetworkServer.Spawn() synchronises an exact copy of the object to all clients, so what you can do is:
- instantiate the chest on the server
- set some variable on the script of the chest that decides what to spawn additionally (and locally)
- make sure that the chest spawns the thing according to that variable on Start()
- call NetworkServer.Spawn()
Hope that gives you something to start with.