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"

Multiplayer Variables, Game Instance, and Objects

So I have just been making a multiplayer game. A simple shooter. When I get into a session with a friend, i switch my weapon to a sniper rifle. Everything is working fine until here. On my screen, he pulls out his rifle as well, but not on his. The same thing happens for him. Whatever weapon he is on, it looks like I'm using that one too on his screen, but not on mine. I think that it is because the characters use the same objects for each pawn, and I'm setting them to visible and not visible based on what weapon is out. I think that it must be setting all weapons on my screen to that weapon, but since we have separate game instances it tailors to the person viewing it. I'm storing my variables in a game instance to access them across blueprints, but it seems to be changing them for each player in the game.alt text

https://imgur.com/a/XyzzCaA https://imgur.com/a/REhTtDd

Product Version: UE 4.19
more ▼

asked Apr 26 '18 at 01:57 AM in Blueprint Scripting

avatar image

6 1 2 6

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

3 answers: sort voted first

One thing I see is you don't have any Switch on Authority. Authority means its the server character and not a client and remote is obviously the client.

So you can think of it like this Server is the boss that controls everything. So the Server can do whatever it wants... but if it a client you have to ask the server to do stuff for the client. Like in your example set visibility.

alt text

In this example the authority(server) can just go and change the visibility and everyone on the server will see it change. But if the client wants to do it, it has to ask the server to do it for him and then the server replicates it to everyone else to see.

Also game instance is only on server side. So clients won't be able to get that data. So again you have to tell the server to its game instance and then replicate that variable to clients.

more ▼

answered Apr 26 '18 at 02:22 AM

avatar image

405 18 11 31

avatar image EvilTeliportist Apr 26 '18 at 03:00 AM

Thanks for the unbelievably fast response. I'll try this tomorrow with my friend. Since you seem to know what you're doing, can you tell me if there is an easier way to test multiplayer capabilities? Right now I'm packaging the project every time I need to test and sending it to my friend. Any suggestions?

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

Lol. Just a coincidence that I log in the same time you posted the question.

To test multiplayer. Find the Play button on top and beside it there's a small arrow pointing down. Click on the arrow and somewhere it says 1 player. Change it to 2 or more if needed. Don't forget to click the up arrow on my answers to let everyone know it's resolved. Thanks.

more ▼

answered Apr 26 '18 at 06:48 PM

avatar image

405 18 11 31

avatar image EvilTeliportist Apr 26 '18 at 08:57 PM

What blueprint are you in when doing your first solution?

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

That would be the player pawn or character blueprint. Because in your case the player presses a button then ask the server to do the changes for it or shoot a bullet or something.

more ▼

answered Apr 27 '18 at 12:29 AM

avatar image

405 18 11 31

avatar image EvilTeliportist Apr 27 '18 at 02:33 AM

OK. So I switched everything to proper networking based on this PDF, and I've gotten a lot of it to work. The first problem I had is fixed because I switched to storing my players variables on a player state instead of a game instance. Now the problem is that when I switch weapons on client or host, I want that to change that players weapon on everyone else screen. Basically I cant see my opponents switch weapons. I think that I need to set the visibility of these objects in something other than the player state, because it is only setting the visibility for that player, but I don't know. You have any idea how I could do this?


avatar image EvilTeliportist Apr 27 '18 at 02:38 AM

UPDATE: I got it to work by setting each component of the pawn to replicate. But now only the host shows the weapon switching. On the client's screen, the client can switch fine, but on the host screen it looks like the client has all three weapons out at the same time and never changes.

avatar image EvilTeliportist Apr 27 '18 at 02:44 AM

UPDATE: The client cant switch weapons i lied.

avatar image SkeetonYu Apr 27 '18 at 07:35 PM

Can you show me a screen shot?

avatar image EvilTeliportist Apr 27 '18 at 07:38 PM

alt text alt text

1.png (506.1 kB)
2.png (482.9 kB)
avatar image EvilTeliportist Apr 27 '18 at 07:40 PM

alt text

3.png (407.9 kB)
avatar image EvilTeliportist Apr 27 '18 at 07:49 PM

alt text

3.png (1.6 MB)
avatar image SkeetonYu Apr 27 '18 at 08:40 PM

You're not using switch has authority... You have to use it if you want things to replicate.

avatar image SkeetonYu Apr 27 '18 at 08:42 PM

Anything you need to replicate must be told to the server to do it. Everything you have is gonna work on server because its the server but the client won't work because he is not telling the server to do it for him.

Please refer back to my first answer.

Or watch this about replication: https://www.youtube.com/watch?v=hlDWovBcu7E

avatar image GarnerP57 Apr 28 '18 at 09:31 AM

Switch has Authority is just filtering the flow of the one with authority and the one without, it has nothing to do with replication. Input events are only triggered on the owner of that actor so no need to use a "Switch has Authority" here. In order to let the server know that you pressed a button you either need to call a "RunOnServer" event or call a networked function.

avatar image SkeetonYu Apr 28 '18 at 04:08 PM

Obviously in his game the server is also a player. So as a server you gonna call a RPC everytime?

Look at my first answer the remote calls RunOnServer but not the server because that's just redundant. Also he'll need to use Switch has authority when it comes to things that you don't want the client be able to do, like make thier health at always 100 or set their movement speed aka speedhack. He'll also need it to change stuff locally, ie HUD stuff. It's just good practice and helps actually understanding how network replication works.

avatar image GarnerP57 Apr 29 '18 at 10:06 AM

If a server make a RunOnServer on itself no RPC is sent. Where should it send it?. It simply do the event so nothing redundant is done.

avatar image SkeetonYu Apr 30 '18 at 01:59 AM

Yes, but still needs to use it when changing variables. I understand what you mean but you might sound like he shouldn't use Switch has Authority at all.

avatar image GarnerP57 Apr 30 '18 at 01:37 PM

No that is not my intent. When both server and client is doing the same event then "SwitchHasAuthority" is very important to split the flow when necessary.

avatar image GarnerP57 Apr 29 '18 at 11:20 AM

The hud class only exist locally so also here Switch has authority has no meaning.

(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