Help with a solution to track all players coherence sync'd objects

Hi folks,

I’m looking for some advice on the best practice to apply to a problem I’m tackling in Unity with Coherence please?

Game type: Multiplayer, 2 - 8 players using Coherence “rooms”
Platform: Unity 2022.3.4f1, Coherence SDK 1.0.0

Situation: Once users connect to a room, I have the coherence bridge call “Spawn” methods of a player handler game object in the scene (“DeSpawn” is called on disconnect). The player handler game object and associated script instantiates the player a coherence sync’d game object that the player controls to compete against other players. All works great.

Problem: I’m building out map / radar functionality and I’d like to have a centralised list of all the player game objects, as a source of truth for this functionality, kept up to date when players leave (disconnect) or are destroyed and respawned. This should be able to be referenced by various components (map, radar etc) to get up to date positions of all players game objects transforms. Currently I’m using FindGameObjectsWithTag to get a list of all the player game objects, but i’m aware this is resource intensive and likely not the best approach to be doing every frame! I’m also aware that i cannot sync Lists or arrays etc

Can you advise me on the best approach to architect a solution, or any guidance as to where to read up further to come to a solution myself?

Many thanks!

1 Like

Hi Ben, have you seen the ClientConnections feature? https://docs.coherence.io/coherence-sdk-for-unity/client-messages

It allows you to receive information about all connected clients. You could use this info to build your own system that then does what you need, like keeping track of their position, etc.

Will that work for your needs?

1 Like

Thanks Brit, much appreciated - I do use client connections, but have not explored it for this use case - presume you would retain a list on your connection and use commands / events as and when others join to populate a list of game objects that are connected.
I’ll dive into the docs again - thanks very much for your guidance!
Ben

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.