0
\$\begingroup\$

I'm very new to Mirror in Unity but I have a lot of experience in Network-programing.

I'm currently trying to create a Game, where the Player's data is stored on the client, and can join different games (not concurrent) with his/her character. (Likely to Terraria)

So I can't use the automatic Player creation of the default NetworkManager class. After clicking "Join/Host" in our Main-Menu I want to change to the scene the player has played in, Hosting/joining a server and create the player on the server with the specific position...

I have tried now multiple attempts to do this, but none of mine seemed to work. Am I the even possible to have the players in different scenes with ease? Where/When should I create the Player so isn't null on the Server?

\$\endgroup\$
1
\$\begingroup\$

You will need a custom NetworkManager and just handle the spawning/ setting there. But keep in mind if you trust the client with the players data, it is open to manipulation.

public class BasicNetwork: NetworkManager
{            
    public override void OnServerAddPlayer(NetworkConnection conn)
    {
        Transform startPos = GetStartPosition();
        GameObject player = startPos != null
            ? Instantiate(playerPrefab, startPos.position, startPos.rotation)
            : Instantiate(playerPrefab);
        player.GetComponent<Player>().playerName = "Player " + Random.Range(0, 1000);
        //Gives the client authority
        NetworkServer.AddPlayerForConnection(conn, player);
    }
}

In the Room Example from Mirror you can find another example for passing data from the Roomplayer to the Player located in the OnRoomServerSceneLoadedForPlayer (which could be used if I understand your question correctly). Your RoomPlayer is like a Lobby and you could make a custom loading from your local clients data there - even if it is like a 1 Personlobby to get ready.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.