#Spawn Players

1 messages · Page 1 of 1 (latest)

warped hearth
#

So in the lobby, I have the host create a network list that contains the ugs player Id, CharacterId and Player Name.

Then I have a spawner that spawns the host OnNetworkSpawn. And then spawns each client with OnClientConnectedCallback.

When the character is spawned, it asks the owner for their ugs player Id and then looks up in the list to give them the characterid which then changes the sprite accordingly. The issue is that the sprite is only changed per owner. What would be a better way to do this so that each player sees all sprites for all players?

signal ocean
#

Sprites are not synced on the network. Easiest way would be to have the character ID be a network variable and each client can see the update and change the sprite accordingly

warped hearth
#

Thanks! I got it working!

#

Issue I'm having now is that right before the host starts the game I create a roster using the UGS Player Id, Client Id (don't have yet), CharacterId.

Then when I spawn each player, I have the client run a serverRPC to find their place in the roster using their UGS Player Id and then update their Client Id. This runs, however the list is never updated:

    [Rpc(SendTo.Server, RequireOwnership = false)]
        public void UpdateClientIdFromUgsPlayerIdRpc(FixedString64Bytes ugsPlayerId, ulong clientId)
        {
            for (int i = 0; i < Roster.Count; i++)
            {
                var row = Roster[i];                         // take a copy
                if (!row.UgsPlayerId.Equals(ugsPlayerId) || row.ClientId == clientId) continue;  // compare like-with-like
                var oldClientId = row.ClientId;
                row.ClientId = clientId;                     // mutate the copy
                Roster[i] = row;                             // <-- write it back to the list (important!)
                Debug.Log($"We changed ClientId {oldClientId} to ClientId {clientId}");
                break;                                       // stop at first match
            }
        }

Thoughts?

signal ocean
#

That should be updated on the server but not on the clients unless that list is a NetworkList or NetworkVariable<List>

warped hearth
#

Right. It's:
private NetworkList<PlayerConfigNet> Roster = new();

But the weird thing, is that it isn't updated for the server.

#

When I run that, it doesn't trigger the OnChange Event.