Multiplayer casting/variable issues

Ok so i have a character class setup to allow me to do damage, receive damage, kill monsters, i have a health meter, everything works GREAT in single player or on the server… but in multiplayer none of the other clients receive any updates from any of my variables at all. This causes the game to load up with all the clients having empty life bars, empty widgets, and monsters that can’t damage them. The HUD loads correctly, but can’t access the variables on the player character when on a client. Say i have a variable called “Character Name” on the firstperson character, on the server it retrieves and returns the name no problem… but on a client it just returns “client 2” regardless of which variable i retrieve. I feel like i am missing something important and very obvious, that is causing my entire setup to crash and burn when done in multiplayer. Could i be casting to the player character incorrectly? Everything that interfaces with that class stops working in multiplayer, i just don’t know how to fix it. I intend to make an MMORPG, so i will need to get many clients all working together.

Hi,

from your post it seems that you completely missed the replication part, which is … a bit more complex.

As a starter:
https://www.unrealengine.com/blog/crash-course-in-blueprints-replication
and
https://docs.unrealengine.com/latest/INT/Gameplay/Networking/index.html

Cheers,

Even if the replication was set up wrong… wouldn’t the local replication on each client between it and the widget blueprint it called still work correctly?

Depends on where the widget is created / called / updated. Is it done in a Server-Function? Is any replication set up for the name - variables that read different on client and server (seemingly not, otherwise the clients would have the same value as the server). Replication can be wrong in so many ways and its always good for a surprise :slight_smile:

Anyway, the bottomline is that if you want to do a Multiplayergame (not even talking about an MMO-like thing), you have to become best friend with replication (or, if you really want that, integrate an external networking framework into UE4). Also, you will have to set up the whole logic from ground up with replication in mind, or you will be refactoring pretty much everything you already made, multiple times.

Cheers,

I set the name variable to replicate, other than that i haven’t set any of these functions or variables to run specifically on the server. The widget is created in the characters begin play section and also bound to a variable there for future use, but when i try to call that to get the variables, it does not see anything but “client-2”. The widget being called here is a simple one that puts health/experience/etc bars on the screen and attempts to retrieve variables from the character blueprint to update those bars. The bars all show up as expected, but do not update for client characters. Casting from from playerROOT_Package to the widget also works, because playerROOT is creating the widget and throwing it straight into a variable. cast to playerROOT_Package from the widget is also failing, and im not sure why.

You don’t want to create the widget in the character BP, do it in the controller. You’re creating multiple instances of the widget at once since multiple instances of the character are created.

The cast is failing because your reference is incorrect. You’re referencing nothing as your index appears to be nothing…

As indygoof said, you really need to fundamentally understand how client/server interaction works before working on anything serious. Start with some basic communication testing. For example, make two clients that can damage each other or something, and have an “HP” widget update the values accordingly. That’s a nice super simple thing to start with.

The index is 0 and still fails. What do you mean im creating multiple instances of the widget?

One character is created for every client + the server. Hence, one player will have multiple widgets. Do a simple test to see what I mean: Create a button and have it remove itself. You will see that you’ll have to do it multiple times, depending on how many clients are activated.

And as for the cast failing, where is it being constructed? The widget? Also, player root is the character BP right? Where the widget is being made?

Yes player root is the character BP, and also where the widget is being made. You almost make it sound like putting a widget in the character creation will cause a widget to be created on everyones screen repeatedly for every extra player that joins.
The failed casting from the widget to the character blueprint… i try to cast to it using player controller, or am i doing that wrong?

Well I just tested and I guess it must have been a bug, because that’s what used to happen. Nevermind on that.

If you want the cast to succeed use the “Get Owning Player Pawn” node (Just tested and it worked for me)

If you have issues still but don’t mind starting from scratch try using eXi’s video - YouTube

Please note, this video is pretty old. There were a bunch of new version in these 7 months, so i can’t guarantee that it’s not outdated somewhere.
But it should still help getting the base idea (although i can’t really remember what stuff i told there).

Getting owning player pawn did not work for me, but i did find a workaround. I set the variable for the widget immediately after creating it inside the character blueprint, while still in the character blueprint, just had the character blueprint pass self to the widget variable.