Multiplayer Play Mode get player id

Hello,

Is there a way to get the virtual player Id (1-4) when using Multiplayer Play Mode?

Looks like Unity.Multiplayer.Playmode.CurrentPlayer doesn’t have any API for that. I noticed the code in Unity.Multiplayer.Playmode.VirtualProjects.Editor.VirtualProjectsEditor (which is only internal) and I could reimplement it, but I’m wondering if I’m missing something obvious that would avoid that.

My scenario: I want so name each character in my game with their virtual ID so I can distinguish them on the screen easily.

Thanks,
Victor

So for example

In my game my server reports

          NetworkManager.Singleton.OnClientConnectedCallback += (clientId) =>
           {
               Debug.Log($"Client {clientId} has connected to the server");
           };
           NetworkManager.Singleton.OnClientDisconnectCallback += (clientId) =>
           {
               Debug.Log($"Client {clientId} has disconnected from the server");
           };

You could assign the clientid to something, such as name "Player "+clientID, its not perfect but it makes them have unique names at least

Thanks!

I should have mentioned that we’re not using Unity’s Netcode so using NetworkManager is probably not an option for us. We just use Multiplayer Play Mode as a replacement for ParrelSync.

I ended up duplicating some code in Unity to make it work:

#if UNITY_EDITOR
        private static string GetPlayerIDForPlayMode()
        {
            // The code is a duplicate of the code that's not public in Unity:
            // com.unity.multiplayer.playmode\VirtualProjects\Editor\Config\CommandLineParameters.cs

            const string vpIdArg = "-vpId";

            var args = System.Environment.GetCommandLineArgs();
            foreach (var arg in args)
            {
                if (arg.StartsWith(vpIdArg))
                {
                    return arg.Replace($"{vpIdArg}=", string.Empty);
                }
            }

            return string.Empty;
        }
#endif

but I still feel that something like this should be a first class feature of CurrentPlayer #my2c