Converting A Singleplayer Blueprints Game to Multiplayer
I am working on a singleplayer game which I hope to eventually convert to multiplayer. I do have a very basic knowledge of replication and some stuff about how multiplayer works, but not much. It has come to my attention that perhaps I should be starting to think about multiplayer sooner, to avoid making the game difficult to convert in the future when it has more features. However, I am not really sure what I should be doing.
As I understand it, the way replication works is that if the client wants to spawn something that needs to be seen by all players, they need to tell the server to spawn it as well as set the class of the thing they are spawning to replicate. First question, is this correct? Secondly, how does the client communicate with the server to tell it to spawn something? Could someone explain simply what I would have to do to make it so that if any player when they pressed a key could spawn an actor, say, and all other players could see it.
Also, are there any other things that I should know and bear in mind other than the issue I just mentioned? (I understand about sessions and how you would make a main menu setup with hosting and joining so that isn't an issue, it is more gameplay I am worried about)
And finally, would you recommend that I keep going with singleplayer exactly as I am doing (with no considerations for multiplayer), make the game multiplayer right now before I add too many features, or keep going with singleplayer but work slightly differently based on the answers to the previous questions?
If anyone could help answer some or all of my questions it would be greatly appreciated.
asked Aug 08 '18 at 08:09 AM in Blueprint Scripting
You only need to spawn it on the server and it if the actor is replicated it will also spawn on the clients.
When you create a custom even in the properties you can set the RPC mode. If you set this to "server only" the event will only be executed on the server. In the same way you can set it to "owning client only" in case you want the server to call an event on a specific client, or "multicast" if you want the server to call the event on all clients.
For multiplayer it's very important where your functions, events and variables are located. You should read up on how Game Instance, Game Mode, Game State, Player State and Player Controllers work for multiplayer. Quickly: Game Instance is something that isn't replicated and can't have replicated RPC events. Everyone has their own Game Instance. Game Mode is something that only exists on the server. Game State is something everyone has. Player State is something everyone has for every player. Player Controllers is something all players only have their own of except for the server who has a Player Controllers for every player.
So if right now for your single player you are putting everything in Game Instance or Player Controllers that might not work.
I would suggest that if you want your game to be multiplayer at some point you start with it now. I did for my game after working on single player for a while and I already had to make a bunch of changes that were much easier to do now than later.
answered Aug 08 '18 at 09:34 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here