Search Unity

Resolved System Choose Skin

Discussion in 'Netcode for GameObjects' started by kauanvicto700, Nov 19, 2022.

  1. kauanvicto700

    kauanvicto700

    Joined:
    Feb 2, 2022
    Posts:
    2
    I'm trying to make a system to be able to choose the skin at the start, I just wanted to change the NetworkManager's PlayerPrefab but I wasn't successful so I decided to instantiate a different player Prefab for each player but it instantiates more only for the host, the client is on the start screen as if it had not connected, but his Prefab instantiates on the host.
     
  2. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    229
    Did you network spawned the prefab when instantiating on host?
     
  3. kauanvicto700

    kauanvicto700

    Joined:
    Feb 2, 2022
    Posts:
    2
    I managed to solve it I just needed to add the Prefabs in NetworkPrefabs in NetworkManager
     
  4. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Hi @kauanvicto700 , I wouldn't recommend this approach, as it forces you to duplicate all player's script on different prefabs. Instead, I'd use a ServerRpc to make the client pick the skin, and a ClientRpc to notify the picked skin to all clients. You can use an ID to say what skin was picked, and load the skin prefab at runtime as a child of the player
     
  5. TestifyNow

    TestifyNow

    Joined:
    Feb 9, 2016
    Posts:
    24
    This does not support newly connected clients. NetworkVariable is a much better choice, as it gets synchronized when a player connects. BOOM headshot.
     
  6. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Correct! I was assuming that you make people choose only when everybody is in the lobby. But yes, if that's not the case, NetworkVariable is a better choice.