Getting other player nodes on lobby join using SteamMultiPlayerPeer

Godot Version

4.3 stable Godot SteamMultiPlayerPeer

Question

Hello guys, I am currently working on a basic lobby system.
For that I use the Steam API with the precompiled SteamMultiPlayerPeer version of GodotSteam.

I first add the player in using this basic function after connecting it (multiplayer.peer_connected.connect(_add_player_to_game)):

func _add_player_to_game(id: int):
	print("Player %s joined the game!" % id)
	
	var player_to_add = multiplayer_scene.instantiate()
	player_to_add.name = str(id)
	
	_players_spawn_node.add_child(player_to_add, true)
	return player_to_add

I use the almost same function of getting the lobby members like in the GodotSteam documentation, whenever a player joins.

func get_lobby_members() -> void:
	# Clear your previous lobby list
	GlobalSteam.LOBBY_MEMBERS.clear()

	# Get the number of members from this lobby from Steam
	var num_of_members: int = Steam.getNumLobbyMembers(lobby_id)

	# Get the data of these players from Steam
	for this_member in range(0, num_of_members):
		# Get the member's Steam ID
		var member_steam_id: int = Steam.getLobbyMemberByIndex(lobby_id, this_member)

		# Get the member's Steam name
		var member_steam_name: String = Steam.getFriendPersonaName(member_steam_id)
		
		var player
		if member_steam_id == Steam.getLobbyOwner(lobby_id):
			player = _players_spawn_node.get_node("1")
		else:
			player = _players_spawn_node.get_node(str(member_steam_id))
		
		GlobalSteam.LOBBY_MEMBERS.append({"steam_id":member_steam_id, 
						  "steam_name":member_steam_name,
						  "player": player,
						  "position": GlobalSteam.SPAWN_PLATFORM[this_member]})

As you can see I added extra fields called “position” and “player”. There the playernode and the spawnnode should be stored to later set the individual spawns of the players.

So the procedure is as follows: 1: Player Joins → 2: Playernode gets added → 3: Playernodes of all players are retrieved → 4: Playernode is set to specific position.

The problem however lies with the access to these player nodes. For the host this works without a problem since he’s added and then placed. If I join however step 3 fails because the other players aren’t in the tree yet and they’ve been instantiated beforehand on the other peers.

Since I want to place the players immediately when I join the lobby I somehow have to retrieve the other player nodes when I join.

Is it possible to somehow manipulate the spawns of the nodes in the MultiplayerSpawner so whenever the other players are synchronized/spawned in I can assign them a spot? Because otherwise I wouldn’t know a way of immediatly accessing the other player nodes while the new player itself is spawning in.

I usually handle this with a data manager that each peer has. By default it stores the players information and settings relevant to gameplay.

When a player joins it sends it’s data to the host the host spawns a MultiplayerSynchronizer that will auto spawn on all the clients with a MultiplayerSpawner. The player data is then transmitted from the host to all the peers.

When a node is spawned there is a signal that adjacent systems will query the new information and update UI and player scenes etc.

Here was a prototype to set it up and pass data around.