Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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.