Two Multiplayer Questions (Function + Variable replication)

Hello everyone!
First off I want to mention that I’m about to go nuts over this. Networking seems to be a topic that most people seem to avoid and even in Answerhub my questions are mostly ignored. This is not a case of “build my code for me”, I am genuinely baffled about how network works in UE4. And yes, I’ve seen all the tutorials and checked out all the content examples, read documents about it etc, but still there are a lot of questions that are never answered. (sorry for misleading topic, it’s three questions)

Maybe if you can help me find out how to get these two problems working, I can finally make sense of what is going on.

  1. Calling a UMG function from a client

    Here’s how I add the hud to each player. It works and all numbers show up for each player just fine. However, when I try and call a function within the UMG, it only works on the server. It seems to forget inbetween BPs that the player hud is actually set to anything, instead it shows me “current value = none”, but if that’s the case how do all the numbers show up correctly?

  2. Having smooth crouching in multiplayer

    The funcions itself work for both client and server. You can crouch just fine! Except that the camera position starts to jitter heavily when the client goes into crouch mode. It seems (again) that the variable of the camera vector is forgotten or somehow doesn’t work correctly in multiplayer. Maybe I haven’t set it up correctly. But since it doesn’t matter for the multiplayer, I just set it up locally. But even if I set it up so it replicates, it still jitters like crazy.

  3. Turning Flashlight on and off

    After having problems with the other multiplayer features, I thought this one might be simple. Just use a RepNotify, right? Well, kinda. But in this setup, the server works fine, but whatever the client does is not getting updated on the server. Even though the description of RepNotify says “Variables that are marked RepNotify, have a special function called automatically any time the value is changed, on both Network Authority and Remote Machines.” So why does the server not see any change if the client toggles his flashlight?

Sorry for rambling, but these issues are driving me crazy. Please if anyone whos what magic is necessary to get this working, please help me understand it.

Event Begin play is run on both server and client, make sure to switch authority depending on what you want to run what.

The other and main thing to watch out for is using the “self” target when using an event that is run on server. That’s the server’s “self”.

Also make sure you have the event correctly setup to replicate server, or client.

On crouching start event notice that it says replicates from client executes on server. What you need the server to do is target the client that the crouch press came from, not try to run crouch on the server, so you need the target to be the originating client.

I’m struggling with this for a while now, could you be a bit more specific?
In my sprint BP there is also nothing connected to the “self” pins and it is still working in multiplayer fine. So I doubt this is the reason this isn’t working.

In bottom right of picture 2 are you expecting the On Rep Current Camera Location to be called?

In picture 3, all you would need to do to make that work is to create a new event that replicates to server. Call that from your input, then do the flashlight is On = Not Flashlight is On. Then the On Rep Flashlight Is On will be called on all. If it’s run on a client it will only get run on that client. if it’s run on server all clients will run.

If you add print string at the start of certain events to see where they are running it can help so you know what’s going on. Some events like Tick and Begin play are run on both server and client, while other things like key press are only run on client.

There is only 1 rule to rule them all, all replication happens from server to client, no exception. If you try to do something local and expect it to happen to other clients, good luck, ain’t gonna happen.
I know you said you read all the stuff and checked all the videos, BUT, check the links in my signature about RPC and replication before you continue.

Holy sh*t it works! The flashlight is now working :smiley:

The camera location is currently handled locally only, since it is not needed to be sent via server. But still the camera starts jittering heavily when the client goes into crouch mode. Does that have to do with the lerp not working over network or something? I’ve tried adding the “self” as pins to the server functions but it doesn’t help.

edit: Thanks Penguin

I still can’t figure out how this works.
The two BPs I posted remain the same, I’m constantly trying out new stuff, but in the end it just doesn’t work.
The flashlight does work now, the other two - I’m still completely baffled about how this replication thing is supposed to work.
Thanks for the info Penguin, but still there is nothing explained about what I’m asking here.

I’ve seen that replication is quite a beast to understand, so why are there no advanced tutorials or at least examples on this matter? I’ve seen the Epic tutorial and BP example network map, but they are no help to me. Things that are totalls untouched by these include UMG Widgets (HUDS), components, player controllers, game state etc.
How do I access them in multiplayer? There is nothing about this topic, even in Answerhub these kind of questions are getting ignored again and again.
For example I’ve never seen anyone say how a multiplayer HUD like in Left 4 Dead, Payday or if you will WoW (groups that see the status of other players on their hud). As far as I can tell from the answers given in Answerhub, these kind of things are impossible in BP since you can’t access who is what player from a network session.

My first two questions, getting the HUD to work (it shows up and numbers are correct on client and server, however functions are not called!)
and getting a smooth crouch for both players. The camera starts jittering for the client and it also doesn’t go down all the way.
Can someone explain what I’m doing wrong?

I feel bad to keep asking these questions over and over, maybe I’m just a complete moron, but I just can’t find any answers or help for this topic and it’s the center part of my current game. Do I need to pay someone for consulting on this? Why are the Epic wiki docs so short and leave so many questions open? This is so frustrating…

What blueprint is picture 1, what do you mean the functions aren’t called but numbers are correct? Have you tried adding print string into the functions you don’t think are called to make sure they aren’t called?

In bottom right of picture 2 you have On Rep Current Camera Location, is that supposed to be doing something?

Question 1) The image shows how the HUD is setup for the players. I do this inside the HUD Blueprint class. The setup works and every player sees his own health and ammo on their screen. I also have a function that is called whenever a player finishes interacting with an object (it shows a flashing logo). This function does not get called for clients, only for the server. I used a breakpoint to check and it seems the HUD variable is not set for clients, even though I set it up in the HUD class.

Question 2) The screenshot was made in between me trying out different stuff to make it work. This is how it looks right now (ignore the warnings, this is due to moving stuff around):
Here is the start. I just do a check if the player is currently crouching. If so, it tries to stand up (has to check locally for barriers first). If not, it starts crouching and updates the camera.

A check for obstacles if the player attempts to stand up. This is just a simple sphere trace for objects above the player. If no objects, then do the uncrouching motion and move the camera. If objects - well this is left open, but in the end it will display a message on the HUD saying “you can’t stand up here”

Here we have the replicated events. The server changes the movement speed and capsule height of the player that is crouching. This seems to work fine, as I can see the height change on both server and client and also the client fits under a table when he crouches. However right now there seems to be a bug with this, since it is not updated correctly (when client stands up, he goes into crouch mode on server and vica versa - this is probably since I’m changing all kinds of stuff around and broke something)

This is the final piece. Here, I just locally update the camera with the same motion as the capsule height changes. This only works for the server, but the client just starts jittering heavily up and down whenever he is in crouch mode.

about Q1, HUD is essentially a client side thing, so make sure you just manage the variable replication instead of replicate HUD, server do not need to host or keep a reference of a HUD object, nor should a HUD/widget object replicated.

about Q2, I wouldn’t say your setup is wrong, but it will be prone to conflicts as timeline is good for something that fire and forgets, not something used to control state.
Say, how about you call a custom even after you set walkspeed ratio, instead of using timeline, just try to catch up the number for your lerp, ie if your goal is 96 for stand, 48 for crouch, make a select and use your isCrouching to get the “goal” height, plug to B.
Then, your current height is A, and alpha is a fixed step to control animation speed(alpha = step/(goal-current) ). At the end of this custom event, if your goal height is not reached, call it self again until your goal is reached.
It’s probably not going to be as smooth as if you blend from 48<->96, but this gives you the ability to do it on the fly without worrying execution conflicts(ie. press crouch, timeline running from stand to crouch, and the stand, while the animation is still playing.(which may be why it cause jittering.)

also, if you really want smooth lerp, you can still use it as is, but alpha would be (current height+step)/(stand half height-crouch half height). I use this before on experiment to make hovercraft so it always try to dampening and keep certain distance without using timeline as you are constantly moving.

I would suggest simplify it just for testing. first you shouldn’t need the “Teh Self” here. What I would suggest to test this, create a “crouchstartstop” Event that is replicated to server. The event is very simple first it set’s “Is Crouching” bool = NOT “Is Crouching”. Then branches from “Is Crouching”. If true Set capsule half height to 48, if false set capsule height to 96. Have the input action crouch simply call this event.

Alright, here is the whole setup:

Server can crouch down quite slowly and stands up instantly. This also shows up on client. If server runs around while crouched, client sees him jittering up and down randomly.
Client sees heavy jittering of camera up and down when trying to crouch. The server sees the client go down slowly and stand up instantly.

Ok good, that is what I expected to happen. That would be where the problem is

How else would I do crouching? The original “crouch” that you can use from the character does not work in multiplayer and even if, it looks terrible as it changes instantly to crouch and uncrouch without any kind of motion or blending between camera heights.

are you using the animation starter pack?
Or just using the default ones from template?
the crouch moving jitter probably results from having no proper state for animation state to blend to.(ie. while moving it tries to play stand walking, but trys to revert back to crouching as soon as possible when there are no inputs.)
Also why you see jitter from client side as it tries to crouch while server still tries to replicate old statue.

I have a fully setup ASP character in 4.4 that works in multiplayer, I don’t know how much it’s broken for 4.6 or 4.7.
You just touched the tip of the ice berg, welcome to Unreal Engine 4, again. :smiley:

No, I’m not using any animations yet - just the sphere collider.

okay…capsule half height(which is the target hight if you crouch) I think they will probably do the blending for you if you use inherit from Character and set CharacterMovement component’s mode to crouch.
(I just recently fix up the animation blueprint I did, so I’ll post relevent part for you.)

But definitely experiment more. the way they do blending is in animation, if you want camera to have smooth blend when crouch is toggled, maybe put it to a socket on your skeleton when you have one.