Multiplayer loading screen progress

Godot Version

4.4.1

Question

I need to sync loading process on the client-side when connecting to my host. I am using the Steam addon to create a lobby and a MultiplayerSpawner to sync my current level with all the peers, however I can’t think of a way to sync loading progress.

Host-side I have a working progress bar, since I am loading the scene on a different thread before adding it as a child under the spawn path. How can I replicate such behaviour client-side since the loading is done through the MultiplayerSpawner?

If you have a variable that stores the load progress, you can use RPCs to set the progress on all clients from the host. For example:

# the script handling loading

var load_progress: float = 0

func update_load_progress(new: float) -> void:
	load_progress = new

	sync_load_progress.rpc(new)

@rpc
func sync_load_progress(new: float) -> void:
	load_progress = new

update_load_progress would be called from the host and call sync_load_progress on all clients to synchronise the value.

If I understood it well you are assuming the host and the clients are loading simultaneously, right? In my project the host starts a game, at any given time a peer can connect to the host.

In this case the host doesn’t update any load progress as they are not loading anything, however the client needs to load the map and all the data. This loading process is “lost” somewhere in the MultiplayerSpawner logic I suppose.

Right now I am “faking” a solution by giving some progress feedback as part of a signal linked to my SteamAPI callbacks. So, for example, when the client joins the lobby the progress is updated by 25%, on successful join another 25% is added, and once spawned the bar is filled. But this is just a work-around and I don’t like it much. I’d like a more straight-forward approach just like how you can get loading progress from a thread.

Hope this makes sense :sweat_smile:

Oh sorry, you’re right. For some reason I just assumed you had a lobby system where all players would join first and then the game would be loaded…

To me this seems like a pretty reasonable solution. I would probably add variables like var total_task_count: int and var completed_task_count: int to avoid incrementing the progress by hard-coded magic numbers but otherwise I don’t know of a cleaner/easier way to do it. Maybe someone else can help though :slight_smile:

1 Like