Local and online Multiplayer in same project

Hey guys,

i am working on a coop game and i have set it up as a local multiplayer. The next step for me is creating an online multiplayer by keeping the local multiplayer. I haven´t found fitting documentation for this question.
If you guys have a hint how to turn a local mutliplayer into a online multiplayer (by keeping the local), it would be nice if you can give me a link or an explanation. (Yeah i read the unreal documentation to onliine/local multiplayer)

Thanks for the help,

I have accomplished multiple players on one machine playing against multiple players on another machine in a local area network. Not exactly online but should work similarly.

Going in you should know a few things:
Player controllers only exist on their own client machines and not on the others, except the server. The server has all of them.

Player controller ids are always -1 for remote controllers whether viewed from the server or the client. But have numbers 0,1,2,etc for local controllers.

all player States are replicated to all machines. Player controllers are not.

player States dont exist at level start or even player creation but wait until after one or two replication cycles to start existing.

The only base class that comes with smooth network movement is firstpersoncharacter and firstpersoncharacter.
Replicating any other pawn class movement results in choppiness which can only be overcome by creating your own smoothing and prediction code.

RPCs require an owning connection. Without it they may execute but not actually work. Client to server RPCs usually work when done via playercontroller which owns connection. Multicast RPCs usually work when done in GameState class.
These can work in other classes but when they don’t then I move them to these and then they work.

Expanding to networked multiplayer you may need to move some logic from your pawn and controller to the player state, and some of the logic from your game mode to game state.

Remember that game mode only exists of server.

Game instance does not replicate over network so it can be used to preserve local machine’s variables between levels.

1 Like

Also the only reliable way i have found to identify specific players across network is via the Player state → player id. It never worked right to use player index Or id from the controller.
Maybe works to use replicated pawn reference though

Thank you for that summary!
My Problem is actually how to keep the local multiplayer. For the local multiplayer i don´t need sessions and replicated variables, i can create a second player just by calling “create player”.

Will the local multiplayer work with the same setup as the online multiplayer? I am just scared if i change all my blueprints for the online multiplayer, that i can´t get my local multiplayer running.

What are you trying to do?
My setup makes it so 4 split screen players on one machine. Play over network against 4 players on a differe t machine’s split screen.

So it is local multiplayer and network multiplayer at the same time. Is that not what you wanted?

Seems like i didn´t express myself very well. I want to have the option to play the game either local with splitscreen or over a network with a friend.

Mine Also can do local splitscreen without networking, using the same code.

If you are in local non network multiplayer then calls to the server just hit the local machine and the game acts normal because the local machine is its own server. If youre worried though you can tell it not to create a session. It is fine either way.

RPCs and replication when running local only multiplayer like split screen, work just fine even thiugh there is no server or clients tryinf to talk to each other. The engine just runs them all like they are normal non networking functions in that case. At least in blueprints it does.

My project also works with the same code to do local multiplayer only. Code that works with both networked multiplayer and local multiplayer will also work with local only multiplayer or even just single player.

However, code that works with local only multiplayer will not necessarily work with networked multiplayer.

Just be aware that networked multiplayer is 5x as complex as local multiplayer so you have a lot of work ahead of you.

Thank you for that anwser, that is what i was looking for. I know that there will be a ton of work, but a lot of stuff to learn as well, so i am looking foward to it.