Confused by new features.

'ey folks, I’m having trouble understanding the intention and flow behind the new networking features, primarily with regards to managing data on player objects.

What I currently understand (and please correct me if I’m mistaken) is that a lobby player takes up some kind of slot on the server and also the client, and then during gameplay an associated (arbitrary) player object is spawned at some location on the game map. I’m assuming this is intended to be, say, a character which is to be controlled by the lobby player?

The confusing part is how (or whether) these objects are somehow linked together or not, and how to go about applying input. In my mind, I would list some variables on the lobby player and change them based on input, and then the character would then read the input from the lobby player (so that it doesn’t get mixed up with which player on the couch it’s supposed to be getting input from).

Is this anywhere close to the intended workflow, or should I try something completely different?

What seems to be the intended workflow is that you have a player control script of some sort on the player, something like this:

[Client]
void Update(){
    // This keeps you from trying to send commands for other players or the server.
    // Doing that generates an error message.
    if (!isLocalPlayer)
        return;
    if (HasMoveInput())
        CmdMove(GetMoveInput());
    if (HasFireCommand())
        CmdFire(GetFireCommand())
}

[Server]
[Command]
void CmdMove(MoveInput input) {
   // ...Handle move input (move the player object).
}

[Server]
[Command]
void CmdFire(FireInput input) {
   // ...Handle fire input (check that the weapon is ready, and activate it - shoot, swing, throw, etc.).
}

So in short, the client generates and sends commands, and the server processes them. You’d then use NetworkIdentity, NetworkTransform, and [SyncVar] to keep the objects synchronized.

1 Like

Hm… perhaps I should refactor my ultimate question: How are the Lobby Player and the Game Player associated? Are they linked together in some manner, and can the Lobby Player be referenced after the Game Player is spawned?

There is a virtual function on NetworkLobbyManager that is called afer the gamePlay player is created

        // for users to apply settings from their lobby player object to their in-game player object
        public virtual bool OnLobbyServerSceneLoadedForPlayer(GameObject lobbyPlayer, GameObject gamePlayer)
        {
            return true;
        }
1 Like

That, I have no idea. I’m still learning UNet myself. Sorry.

You are a fantastic person.