x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Converting A Singleplayer Blueprints Game to Multiplayer

Hi all,

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.

Thanks!

Product Version: Not Selected
Tags:
more ▼

asked Aug 08 '18 at 08:09 AM in Blueprint Scripting

avatar image

MarsMiner
52 6 11 22

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

they need to tell the server to spawn it as well

You only need to spawn it on the server and it if the actor is replicated it will also spawn on the clients.

how does the client communicate with the server to tell it to spawn something

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.

Also, are there any other things that I should know and bear in mind

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.

more ▼

answered Aug 08 '18 at 09:34 AM

avatar image

erikdubbelboer
366 3 4 7

avatar image MarsMiner Aug 08 '18 at 09:43 AM

Thanks for the answer. Very helpful. Right now I have most my code in the player character, and I have some in the GameMode. Stuff in the game mode blueprint is stuff that I would only want to happen on the server anyway, so I probably won't need to make too many changes in that sense. Just to clarify - If I spawn a replicated actor from a client, will the other clients not be able to see it?

avatar image erikdubbelboer Aug 08 '18 at 09:52 AM

Keep in mind that Game Mode is only on the server. So if you have an event on it that you want to call from a client you can't.

If I spawn a replicated actor from a client, will the other clients not be able to see it?

No, only if that client is also the server.

avatar image MarsMiner Aug 08 '18 at 09:57 AM

Ok that answers that.

avatar image MarsMiner Aug 08 '18 at 09:49 AM

Oh and one other multiplayer question I need some help with - right now when I want my player character to communicate with my hud I do Get Player Controller (Player Index 0) - Get HUD - Cast to....... and then do whatever I want. And then I do Get Player Character (Player Index 0) - Cast to BP_Character to send data from the HUD back to the character. When I make it multiplayer, will I have to change all that code to make it a different player index? Or will leaving it at player index 0 work fine? Thanks for all your help.

avatar image erikdubbelboer Aug 08 '18 at 09:53 AM

Player index 0 is always the local player so that should work fine.

avatar image MarsMiner Aug 08 '18 at 10:00 AM

Perfect. I think I will start working on making my game multiplayer right away. Thanks for your advice.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question