Hello, I’m pretty new to ue4, I did learn somes things, I know how to create/“destroy” an HUD, but when it comes to the multiplayer I tried 20+hours, and nothing worked the way I wanted. Everything should have been fine, but nothing worked correctly. So, after a week of not touching ue4 because of that, I would like someone to explain me how to create and remove an HUD in a multiplayer title from scratch (I would like to display the health), or give me any kind of answer so I can see what is wrong on what I did before. Thanks in advance ^^
There are a lot of tutorial about multiplayer and i am a little lost too sometimes,
here people more expert than me could write down a lot of stuff…
But the the way you didnt point any problem speccificly so i assume:
Probably on multiplayer you get problem with, replication and authority.
Who should manage the hud and who should create it, and from wich variable?
The first things is your multiplayer is client-server or on the same machine?
Here you can find all the basics Networking and Multiplayer | Unreal Engine Documentation
here something to start 1.2 - Detecting Network Authority and Remote Clients in Blueprints | Unreal Engine Documentation
Create and handle widgets in your HUD blueprint/class.
Sorry, I didn’t know where to start from exactly ^^
So, I would like every player to get an health HUD on my game, the HUD displaying a percent of the health of the player divided by the max healh, and also the health variable value. Also the health value can change, by taking damage or healing himself, and this HUD has to remove himself from screen when the character is dead. My game is on a client-server.
I already manage to make that in solo, in multiplayer I first couldn’t delete one on only one player, it was deleting all of them, I was on the character blueprint at this time. I learned the Player Controller class, so I created one and used it, but the HUD was stacking on the host of the game. After that, I learned the HUD class, created one, used it, and called it from the Player Controller class (that’s where my spawn fonction belong) but it wouldn’t cast it if I wasn’t the host (and there was no “has autority node there”). That’s where I’m now. I’m going to check the links thanks for the help
The PlayerController class runs for the local player on the player’s machine, and for every player on the server.
However, the server doesn’t have a GUI.
So, the right thing to do is to set up the HUD class to a user widget blueprint of your choice.
In the HUD, the Player Controller will be that of the local player, on the local player’s machine.
Cast the player controller to your player controller class, and use that to read out things like hitpoints or whatnot.
It’s important to realize that you should remove all input key controls from the player pawn/character class. Instead, just have input variables for “amount of running” and “amount of turning” and such, and update the movement component inputs inside Tick(), rather than on controller input events. Move all the controller input event stuff to the Player Controller.
Without the clear Pawn / Controller distinction, you’ll be fighting the networking system and the already-existing systems for the engine, instead of benefitting from them.
@jwatte Is it bad practice to have character related input (movement and camera look) in the character blueprint?
Ok I know that
But the host do right? I mean if the server is hosted by a player, this player have an GUI right? (also, GUI = HUD no?)
So in the HUD, I do the following? (see the picture)
I don’t get this part sorry if you can explain it differently ^^
Oh ok, thanks for the advice
I tried something and remember why it doesn’t work. So, I cast the “create hud” and “remove hud” function (see the picture above) on my pc at the creation/death of my player pawn. But when I’m not the host, it doesn’t want to cast the HUD… If someone can help, everything else is fine without this MAJOR issue
Do not hook the HUD up to the Pawn; hook the HUD up to the player controller. Make the HUD be a Widget Blueprint GUI.
A good place to find the player controller from your GUI blueprint would be in Event Begin Play.
Because widgets are always running on machines that have local player controllers, there is always a player controller owner for a widget, and you can get this controller, and cast it to the class of your specific player controller blueprint. Do that, and assign the result to some variable in the GUI blueprint.
Then, the GUI can read whatever it needs out of that variable, for example using data binding. Alternatively, the GUI can “install itself” into the player controller by setting a variable on the player controller, that the player controller will then use to send values to the GUI when they change. Either approach works.
You will need to add the GUI you create to the player viewport manually. See this page as an example:
The core “HUD” class is basically obsolete – EventDrawHUD is not how to build an on-screen GUI.
The HUD class is created and contained in the PlayerController class as well. So as I said earlier, to keep everything clean and organized, I suggest that you should create and handle widgets inside your HUD blueprint. Just create one and assign it in the game mode.
Here are the important blueprint screenshots.
Creating, remembering, and attaching the widget in the player controller event begin play.
Finding the controller from inside the widget blueprint in its construct event.
Setting up the game mode to instantiate your player controller, and no HUD.
That’s what I had done, my screen is my HUD (already setup in the project settings as the default HUD)
Well, I already did all of that. I might not explained myself correctly sorry, see the screens. I can create the widget on the HUD, show a variable/progress bar, my only problem is that I can’t get cast to the HUD.
So, after someone logged in I call his PC the respawn player function (from the GameMode that I created) 1*
I respawn a pawn there, and call the Create HUD function from my HUD (that I created too) See that if the cast fail, I print an error message 2*
In the HUD I got every function to create/remove the widget 3*
Inside my widget I check the value of the health (I made this into my PC, I know it’s bad but I wanted to try for this HUD (remember more than 1 month that I’m stuck on this)) 4*
And now when I spawn, you can see that the HUD work on the left player (the host) and don’t on the right player… 5*
Did you try it the way I suggested?
- Creating, remembering, and attaching the widget in the player controller (when spawning is fine)
- Finding the controller from inside the widget blueprint in its construct event
- Setting up the game mode (or the spawner) to instantiate your player controller, and no HUD class
It has previously worked for me.
The way you’re doing it right now is only executing on the server. It’s not casting because it’s trying to reach the clients HUD that only exists on the client. You would need to run the rest with a replicated event set to Run on Owning Client in the player controller after Respawn Player.
I’ve always created the widgets off Begin Play in the HUD class. I don’t think it makes much difference doing it there or the player controller. I’ve found the UI can sometimes not be there in multiplayer if you don’t run it off a timer of some sort though. Which I don’t think is any different in either method. The player controller already has references to its HUD too.
I made this in the past (before using the HUD), I tried again now and it doesn’t work, only for the server owner. And putting an owner is useless in an online mutliplayer right? It’s only for the local one no?
What do you mean by instantiate? Sorry, my english is pretty bad
Still doesn’t work, I just put a custom event replicated to client only (see the picture). When you talk about a timer, do you mean an delay like I did? Cause if it’s, it’s still not working
I made it work ! I just had to make the event reliable ! Thanks a lot ^^ but what’s the difference between reliable and not reliable? Also, I can’t promote the cast to HUD to a variable, and use it later without casting again?