Replicated Alternative to LoadLevelInstance?

I have a working level generation system that adds UWorld objects into the current level using the ULevelStreamingDynamic::LoadLevelInstance method, which takes a UWorld and a position and spawns the UWorld at the position. However, this method is not replicated- if the server calls it, it doesn’t exist on clients automatically. Unlike, for example, the SpawnActor method, which does behave this way.

Is there an equivalent method for spawning a UWorld/Level object into the current level which I can call on the server to have it be replicated onto all clients?

Perhaps try doing it from the level since it’s loaded on all clients and the server?

How do you mean? Doing it with what method?

Well, with what I’ve been working with, I’m doing mine straight from the level blueprint. It’s not C++ like in your case, but it’s pretty effective and straight forward…

Ah, I see. So you’re using the LoadLevelInstance node in the level blueprint. Is your level randomized? Are you needing to make sure the seed is the same between client and server?

Yes, I use the node in the level blueprint and I have cases for random levels… For level randomization, I use a persistent game state across the entire game that directs the game into any particular level or random level.

From that specific level, I can load any sublevels and such into that particular level through the level blueprint and talk directly to the game state and set a boolean on the game state from the level to tell it where the game is and execute logic across all clients consistently and also to the map’s respective game mode.

I personally have not found any other way to do this outside of the level blueprint itself. I only use this for loading sublevels and things of that nature. I let the game mode do all the spawning of actors.

I’m not sure if there is a better way but I think you could try adding a reliable multicast RPC on your game state, and then call it from the game mode. Then the function will be executed on all the client/server worlds. In the function implementation you can then call LoadLevelInstance. This will cause the sublevel to be loaded on each client/server.

I’m not sure how it works if sublevels contain replicated actors. It might do the right thing and connect them up, I’m not 100% sure.

I’ve discovered what seems to be the solution in a post on another thread, from user

Essentially, if you override the package names of the levels to match and spawn the same levels on client and server, the objects within that level are replicated. I don’t think there is any way to have just the server do the spawning and have it be replicated on the clients, like with SpawnActor, but this method is close enough for me.

1 Like