Multiplayer - players armor, weapon, etc. doesn't show up when they join session

In the main menu of my game, you can buy different armor sets, helmets and weapons. You can also select a character race and skin color. Your selections then get saved to a player save slot. This all works fine when playing single player (even if you create a session). But doesn’t work when a client joins the session. My sessions are all advanced sessions plugin, and all Listen Server. The server always sees the clients having the exact same characteristics as the server. The clients always see everyone else having their own same characteristics. Example; Server has a dark skin tone, Client has a light skin tone. Server sees everyone with dark skin tone. Client sees everyone with light skin tone. I’m thinking the issue is maybe with my save game… it’s like the each machine can only see data that is from their save game.

Here is how the blueprints work. Starting in the Player Character Blueprint
The BP checks for a save game


Save game is created when you start the game (in main menu), so this is always true in a lobby/session.
This is how load game works. It’s way bigger than this, but I’ll just use the Race as an example. So load game, get your saved race from the save slot and set the skin material and the race class in the BP w/ notify.

Here is the race set notify

The actor class holds the mesh of the race (it’s a fantasy game, so think dwarves, elfs, etc.). It also holds the data to adjust height. The “Skin” material variable was set from the load game, and used to set the base material for the race actor mesh. The race actor, is set to component replicates. The Mesh of the character blueprint is also set to component replicates. My Armor, Helmet and Weapon all follow the same type of logic.

I tried to get around this my forcing ever player to update when a new player login into the session. From the Game Mode. This runs an event back to the character that just spawned. To check the Load Game - which takes us back to the top of the post. Load game will grab the saved classes, and then set it in the character blueprint on Set W/Notify.


image

It’s so strange… what is really stumping me is how all of the characters in the session all share the same thing from the machine. The local machines, “race”, “skin”, “armor”, “helmet”, “weapon” are all the same for everyone in their instance… but on another machine,everyone matches the local machine clients character. Even the server’s visibility is wrong.

Thank you for any help.

I don’t see any RunOnServer RPC Events anywhere?

Correct me if I’m wrong but you want to load the local player settings when a player join a session and share it with the server and it so it can replicate the settings to the other players.

  1. So first you join the server.
  2. Then the local player loads its own local settings.
  3. Then the local player needs to send its settings to the server using a RunOnServer RPC Event.
  4. Then the server can replicate the necessary variables to everyone by using SET w/Notify

You may not need to replicate things like class references since they are normally only used by the Server to Spawn Actors. When you spawn a replicated Actor on the server it automatically gets replicated to the clients if relevant.

thaniks for the reply! My understand was setting a variable w/ rep notify would be run on server? The script for setting materials and meshes is run in the re notify. From the gamemode, I also run that “Update All Player Classes” function - but your right, that isn’t set to run on server, so maybe that fixes it? but the check load game it runs too, will set variables w/ notifiers, so I thought that would take care of it.

what is also strange is. Player 1 hosts the session as a listen server, so they are the server. Then player 2 loads in, as a client. I’d think that if the issue was setting on the server, that at the very least the client would see the server as normal - since their functions will run on server, because they are the server. So I’d get it if the server can’t see the client correctly, but the client should be able to see the server correctly… if that makes sense. But it doesn’t work that way, which is why I don’t get what the issue is

I added some additional blueprints to try to fix this… now the clients always inherit their physical meshes etc from the Server’s character… which is not what I want.

Begin Play - check load game
image

Checks if a save exists, then loads it (in a lobby, this will always be true)

The load game function pulls all of the variables out of the save game object, and sets them on the character and at the end I run either a Server or MC event.
image

Those events then pass the variables of the classes, through the server and then set them with set rep notify via multicast.
image

I also have an event that runs when a player joins, through the game mode.


this then reruns the whole cycle one more time.

I just tested again and noticed something really really weird. When client loads into the session. The listen server player on the client’s machine, has the client machines appearance, but the client has the server’s character appearance… so they are flip flopped… On the listen server’s machine, both characters share the appearance of the server’s characeter.
But then when I launch into the game map (listen server travel to map name), they both appear, but now both of their appearances are both the server machines character…

I think it has something to do with the save game… it’s like the client is somehow accessing the listen server’s personal save game data, and then loading that for their meshes

I made some progress, but still not perfect. The server will now see all clients correctly. But the client sees the server as them themselves. I.E. works great on listen server, doesn’t work on clients. But half way there!

What I changed was, I got rid of the multicasting of the variables. So on character begin play, load game, get variables from save game object and then at the end:

Pass those variables to the Server (since I think client can only load game on client not server??)
image

This will then allow the server to set all of these variables on the server, and replicated through a notify.

I think what is happening now, is the server loads into the game first. So when the client joins, it misses the servers updates. Client loads in after Server, so Server has no issue seeing it all get applied… because I don’t think it’s a replication issue, because the server will load their game, and set it all as a rep notify, so the server’s client should have everything replicated… I think.

I again try to get aroung this via the gamemode, OnEventLogon all players run this event:


But these events have no effect

can anyone help with this? I’ve tried so many things and can’t it to work… thank you for any suggesions

I think you have the wrong idea of a couple of multiplayer concepts.

The “Game Mode” class only exist on the server as it is not replicated and therefore should not have any RPC’s or replicated variables.

The “Player Controller” instances all exist on the server but each client only have their own “Player Controller” because this class is set to “Only Relevant to Owner”.
A replicated array of “Player Controllers” is therefore meaningless.

You don’t even have to save the “Player Controllers” in a variable.
Use “Get All Actors of Class” with the “Player Controller” class but only do this on the server.

Getting your locally controlled “Player Controller” is done by using “Get Player Controller” with player index 0. This also works for the Listen-Server.

Characters are Replicated to all and exist on both server and clients. If you want to make a “Run on Server” RPC on a Character and “Is Locally Controlled” is false then the RPC will fail with a warning in the log.

Recommend you use your Character class with the Event “Event Receive Restarted” and if “Is Locally Controlled” = true then make a “Run on Server” RPC with the loaded Character settings. From here you should be able to “Set w/notify” and use the variables within the Notify callback functions.

Thank you @GarnerP57 got this to work! Couldn’t tell you how good it felt to see this work for the first time testing it online!! Thank you kindly!

For anyone else trying to figure something like this out, this is what I did:

Manually pass the variables through to the server (because it could be loaded on client)

Then have the server actually set the variable w/ notify:

Here are some examples of my rep notifies:

I think my issue was variable was set from loading - which could be ran on client, thus won’t replicate to the server - needs to run server first on rep notify for all clients to see… is my understanding now

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.