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.
  2. 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:
    34
    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:
    223
    Try removing the "(Clone)" on OnNetworkSpawn
     
  3. corypi

    corypi

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