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

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.

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.

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?

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.

What blueprint are you in when doing your first solution?

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.

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?

IMG1
IMG2
IMG3

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.

UPDATE: The client cant switch weapons i lied.

Can you show me a screen shot?

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

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

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.

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.

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.

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

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.