Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved network objects name is not synchronized during instantiation?

Discussion in 'Netcode for GameObjects' started by corypi, Sep 1, 2023.

  1. corypi

    corypi

    Joined:
    Jun 9, 2022
    Posts:
    36
    hi all im having a weird issue where my gameobjects name is not being numbered on the client side. all the info i can find through googling points me to the obsoleted networkView so im not sure how to approach this. here my code it works perfectly on server side but it still has the suffix ("Clone") on the client side

    Code (CSharp):
    1. private void SpawnNewLobbyContainer()
    2.     {
    3.         sceneCanvas = GameObject.Find("Canvas");
    4.         GameObject lobbyContainer = Instantiate(lobbyContainerPrefab);
    5.         lobbyContainer.name = lobbyContainer.name.Replace("(Clone)", currentContainerCount.ToString());
    6.         NetworkObject myNetworkObject = lobbyContainer.GetComponent<NetworkObject>();
    7.         myNetworkObject.Spawn();
    8.         myNetworkObject.TrySetParent(sceneCanvas.transform, false);
    9.         lobbyContainer.transform.SetParent(sceneCanvas.transform, false);
    10.         if (initialLobbyContainer == null)
    11.         {
    12.             initialLobbyContainer = myNetworkObject;
    13.         }
    14.         if (lobbyCount == 1 && initialLobbyContainerHasBeenScaled != true)
    15.         {
    16.             myLobbyContainerTranslator.TranslateContainerPosition(initialLobbyContainer);
    17.             initialLobbyContainerHasBeenScaled = true;
    18.         }
    19.         if (lobbyCount > 0)
    20.         {
    21.             myLobbyContainerTranslator.TranslateContainerPosition(myNetworkObject);
    22.         }
    23.         currentContainerCount++;
    24.     }
    any advice apreciated
     
  2. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    229
    Try removing the "(Clone)" on OnNetworkSpawn
     
  3. corypi

    corypi

    Joined:
    Jun 9, 2022
    Posts:
    36
    that worked just needed to change my logic a bit
     
    lavagoatGG likes this.