Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Unity Multiplayer [Mirror] Objects not properly creating across network

Discussion in 'Multiplayer' started by KingCole32, Jan 13, 2020.

  1. KingCole32


    Aug 15, 2019
    I have a NetworkManager that creates an object on game start as below. This works for the client and host.

    Code (CSharp):
    2. puck = Instantiate(spawnPrefabs.Find(prefab => == "Puck"));
    3. NetworkServer.Spawn(puck);
    The manager also creates the players, each an objects that create objects on player clicks. Players are also created seemingly without issue. I've tried changed this all sorts of ways, but always get variations of the same issue. In the player object, I try creating a new object on click via this:

    Code (CSharp):
    2. ....
    3.    if (isLocalPlayer)
    4.    {
    6.    Vector2 mousePosition = m_Camera.ScreenToWorldPoint(Input.mousePosition);
    7.    if (Input.GetMouseButtonDown(0))
    8.    {                  
    9.          m_currentSwipe = Instantiate(swipePrefab,, Quaternion.identity);
    10.          m_swipeList.Add(m_currentSwipe);
    11.          Cmd_CreateNewSwipe();                  
    12.    }
    13. ....
    15. [Command]
    16. private void Cmd_CreateNewSwipe()
    17. {
    18.     NetworkServer.Spawn(m_currentSwipe);          
    19. }
    This works locally, but isn't creating the object for clients. I feel like I just don't understand where replication is supposed to take place, even after looking at other examples and other questions.

    Any tips would be greatly appreciated. I feel like once I get this one thing down, I'll better understand mirror, in general.
    MentalGames and akuno like this.
  2. Joe-Censored


    Mar 26, 2013
    You are instantiating on the client then calling a Command and trying to spawn the instantiated object on the server, but the server doesn't know what the hell you're telling it to do since it hasn't yet instantiated the object. You need to both instantiate and spawn on the server only.