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"

Loading a local save and replicating the results to all clients?

Hi guys, I'm currently I'm currently struggling to work out how to load a local save file and replicating the results to all other clients. To be more specific I have built a character customisation system which saves all information to a local file to be loaded when the players pawn is spawned, I am able to get the results loaded on to the character in single player fine, however I am a massive noob when it comes to multiplayer. So really the area that I need help with is how I would go about loading the local file to the players character and then replicate this to all other clients so that they see all of the customisations the other players have made. The customisation is added to the characters at spawn so I believe this would need some sort of RPC. I've tried creating a run on server custom event to the singleplayer script but that didn't work. If anyone knows where I'm going wrong it would be great if you could let me know :D

Thanks.

Product Version: UE 4.12
Tags:
more ▼

asked Nov 23 '16 at 03:39 PM in Blueprint Scripting

avatar image

TheLoneJuanderer
10 1 2 7

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

First set all the properties of your Custom Character BP that your local file sets to be replicated. Then create a Custom Event called "Set Custom Character Settings" in your Custom Character BP with Replicates set to "Run on Server" and "Reliable" checked. Add all of the properties in your local file as Inputs to the "Set Custom Character Settings" Custom Event. When you load the file on the client, call the "Set Custom Character Settings" custom event and send in the inputs. The properties will be set on the server and then replicate back to all the clients automatically.

If you have any questions or need more detail, let me know.

more ▼

answered Nov 23 '16 at 04:01 PM

avatar image

Dartanlla
2.6k 62 26 281

avatar image TheLoneJuanderer Nov 23 '16 at 05:23 PM

Thanks for the quick response Dartanlla, that method definitely gave me better results than I've been having and I was finally able to see some customisation on other pawns. The only problem is that on the local players instance all the pawns have his customisation. This happens with all clients. Am I going wrong somewhere because the method you suggested seemed like the right way to to this?

Thanks again :D

Edit: Here is a screenshot as I'm not good at explaining :)

alt text

avatar image Dartanlla Nov 23 '16 at 05:32 PM

Ok, you are really close to getting it working. So when you call an RPC on a character BP and it replicates settings back to all clients it only updates that one character, not all characters like you are seeing. What this means is that your RPC call must be getting called for each character instead of just the one you want to change. Try putting a breakpoint on the RPC call BP node to see why you are calling it for all characters instead of just the one.

avatar image TheLoneJuanderer Nov 23 '16 at 07:11 PM

Okay since I can't test in editor because of steams subsystem I added a print when the RPC is called to see if it was being called a third time, turns out it is D: and I think I had the same problem the other day; since this is a listen server and I'm a noob I can't seem to figure out how to determine between the server its self and the client attached to the server as the client counts as authority? Correct me if I'm wrong (Because I probably am) but it seems like the server is calling it as well as the two clients?

Although I may have set up the character BP all wrong, should I be loading the save within the character pawn or the Player controller?

Really appreciate the help! :)

avatar image Dartanlla Nov 23 '16 at 07:22 PM

Yes, it sounds like it is being called in more places than it should be.

Are you using dedicated server? I have only done multiplayer networking with dedicated server checked in the editor. I have not worked with the Steam subsystem. Even if you don't use a dedicated server, one client is still the server and you can use the Has Authority node to check.

One of the main concepts needed to understand networking is to realize which BP's are loaded on which clients. So in a two player setup, each client has every other client's Character BP as well as their own, but not every other client's PlayerContoller. So you may try calling the Characters RPC to load the settings from the PlayerContoller. This will update only the one character on the Server and then only replicate those settings to that one Character on all clients.

If that doesn't work and you want to post some screenshots of your RPC event and where you call it, I can take a look.

avatar image TheLoneJuanderer Nov 24 '16 at 03:31 PM

No I'm using a listen server unfortunately. Well whenever I use the on authority switch the the authority seems to always be client 1? I'm probably using it wrong? Ah that helps to know, how about the game instance does everyone share one in a multiplayer situation?

Okay so I tried a few different methods along the advice you gave me and I feel like I'm really close. Currently client 1/listen server sees everything he should, however client 2 doesn't see anything change on client 1/listen server? Screenshot is easier :D Left is Client 1

alt text

Here is the BP so far :)

alt text

alt text

avatar image Dartanlla Nov 25 '16 at 12:58 AM

It is hard to tell what all those functions do, but it seems more complex than what I was expecting to see. I was only expecting to see a call to a Run On Server function that passes the charcter data and then a function that uses that character data to set some variables. If visible things need to happen on the client when the settings are changed (like loading a new character model) you may need to change your variable replication to Rep Notify to fire a function on the client when the setting value xhanges.

avatar image TheLoneJuanderer Nov 27 '16 at 01:29 PM

So I ended up using a replicated variable; inside the function I put the function that adds the customisation to the character, and it works! :D

Thanks for the help Dartanalla!

avatar image FardreamStudios Mar 15 '18 at 05:06 AM

I'd really like to see the blueprint. I'm having the same issue. Server has and displays the correct version for self and clients. Clients just see the base model

avatar image CapitalMates1337 Oct 16 '17 at 05:23 AM

You have no idea how much i love u right now

avatar image mightyenigma Mar 15 '18 at 04:42 PM

I have found that even when I set replicated variables on the server copy of an actor, the changes don't show up on the client copy of the actor, and I have to do a MultiCast. So I have lots of multicasts in my BP code.

Seems like it shouldn't be that way....

avatar image Dartanlla Mar 15 '18 at 04:54 PM

Multicasts are quite dangerous and are probably the biggest network game programming mistake most UE4 developers make. The main issue with multicast is that they are temporal and do not permanently change the state of the game. If you watch the networking tutorial Epic made, they warn about this and show an example where a player outside the replication range will get out of synch if you use multicasts (the treasure chest opening example). Personally I only use multicast for temporary effects that are not important to the gameplay, such as very short (2 seconds or less) sounds and effects. If you need to change the state of your game, you will rant to use replicated vars or replicated vars with notify. A replicated var with notify is very similar to a multicast, except it permanently changes the state of the game and will not break when new users login or when players move from one portion of the map to another. Multicasts will break when a new user logs in to the game if they are being used to change the game state.

If your replicated vars are not replicating from the server to the clients, then it means your not setting them on the server or you are setting them on the server and quickly setting the values back before they can replicate. If the values on the server are supposed to be modified based on client input, the correct pattern is to RPC (Run at Server) the value from the client to server, set the value on the replicated var on the server and then let it replicate to all clients while optionally using an on rep notify if you need to run specific code on each client when a value changes (similar to how a multicast works).

avatar image mightyenigma Mar 16 '18 at 03:03 PM

Thank you for clarifying that - I've been struggling to get this to work any way I can, even if it means using those dirty multicasts.This is probably why when a new player joins the game, the other players' tanks don't have the color and name they chose before joining, which through a client-to-server RPC they signaled should be applied to their tank.

(comments are locked)
10|2000 characters needed characters left
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