I am trying to create an online game with split screen multiplayer. In the working local version of the game, I instance the Level as a child of a SubViewport and then set the world_2d of the other SubViewports to the first SubViewport’s world_2d.
I’m having difficulty replicating this in the network multiplayer version. I’m using the MultiplayerSpawner and MultiplayerSynchronizer and can see the level and player moving in the first viewport of the network client, but I cannot get the subsequent viewports to set to its world_2d. I’ve tried using rpc to “call_remote” and set the world_2d, but no luck. Any advice?
Are you instancing one multiplayer API to the root of the scene tree or individually with each world2d branches?
It sounds like you have one world. So i assume the API is set at the root. I think this is fine and correct.
When synchronizing the trees need to match. So if you have nodes under the second player that need to synchronize to a remote player. They too need a second player branch and viewport.
I think the best way to go about this is to have your world branch with players and objects with your view ports with only a camera that follows the player. And maybe some UI. This would allow you to have as many local players as you want as the camera shouldn’t need to be synchronized.
You could split each player into their own world and treat the local player as a remote client if you setup multiple multiplayer APIs with the SceneMultiplayer node. The down side is all your nodes are duplicates running on one machine.
As an example the layout of what I’m thinking of. Where everything under level is synchronized. But the viewport cameras are not and just get updates from the remote transform nodes.
I haven’t done this myself and I’m sure there are other ways to do it. Just keep in mind that scene trees need to be the same under the multiplayer api for replication to work correctly.
Here is an example layout using a SceneMultiplayer approach where you run two instances of the game locally and they act like network peers.
Thank you for your thoughtful response! The issue I was running into when I tried an approach like that was that the levels were separate instances, so player1 wouldn’t see player2 in their viewport. I also tried having multiple cameras in the shared level and setting each camera’s custom_viewport to the player viewport, but that didn’t work either.
However, as I was brainstorming how to make this work, I came to wondering why I was doing it this way. Since the MultiplayerAPI doesn’t seem to support shared world_2ds (at least as best as I could figure out), I figured that it was probably best to leave split-screen for local multiplayer and I’ve changed my online multiplayer mode to a single-screen mode. Not sure if I should leave this open if anyone else runs into the issue, but for me and my game, this is resolved by simply avoiding this type of split-screen.
The video utilizes the first tree layout i mentioned above.
This is incorrect. The api does not care about the worlds, just node paths. The multiplayer API can be setup on any node as it’s “root”. So you can have many multiplayer APIs (and many network peers) adjacent to each other in a single tree.
By default if you set just the multiplayer peer (like many Godot network tutorials do) it defaults to the root node of your scene tree, which will only allow one for the whole tree. (Child multiplayer APIs are not allowed)
It is possible to take that video and make it a network multiplayer with split screen.
You will have to provide more details about your project. What is your tree layout? How do you setup the multiplayer peer? How is player authority given?
Take a look at this post for an example of setting multiple SceneMultiplayer APIs.