Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Question How to have a reference to all player prefabs in netcode for gameobjects unity.

Discussion in 'Multiplayer' started by teixloc, Jan 30, 2024.

  1. teixloc


    Jun 12, 2022
    I am currently making a multiplayer game in Unity C# using netcode for gameobjects and I'm having trouble having a reference to the player prefabs. I can give the players a tag but there is no way to individually reference a player. I know there is OwnerClientId so I was wondering if there is a way to find/reference a player prefab if you have its OwnerClientId. This is just an idea I had but if anyone knows a way to reference player prefabs individually I would really appreciate the help. Thanks
  2. b4guw1x


    Apr 16, 2020
    I have a connected clients controller script. Each player prefab add itself to dictionary on OnNetworkSpawn. I created a dictionary like Dictionary<ulong,PlayerController> and add them with their ID. Since all player has OnNetworkSpawn on each client, it works for me. I think it can solve your problem too.