You are creating the HUD from within the character. This should really by done from within the player controller, since the player controller is persistent for a player throughout a match, while a character can die, so a new one is spawned for the player controller. I would suggest creating the HUD on the player controller’s begin play using a Is Local Player Controller branch, to ensure it is only created for the local player.
I will likely not be handling death in the way that most would, so this is not an issue.
This one I’m not sure about, but it doesn’t seem like a good idea to be creating and adding/removing the HUD from the viewport when toggling it. I think it would be better to create it once, then just toggle its visibility.
Good point, I’ll assess this in the next video.
You are using Get Player Controller when creating your HUD. Any of the “Get XXXX from specified index nodes” are for local multiplayer only, like when playing split screen on a console. When building a real multiplayer game these aren’t good to use. Instead you should use Get Controller and cast it to your player controller.
Player controller 0 is always the local player controller when accessed locally, so this is exactly what we want.
You are storing your array of Players In Game in the Game Instance instead of the Game Mode. The Game Instance is persistent across the life of the executable, where as the Game Mode is only persistent across the life of the match and you probably only care about players that are in your current match. Unless you have plans to later use this array outside of the match for some reason?
We’d want to have this be persistent if we had a lobby of players before the match starts.
You are populating your Players In Game from within the character’s begin play event?!?! That means every time a player’s character dies and respawns for example, they will get added again to the array. There are many other issues with doing this. Instead you should look at using the OnPostLogin event in your custom Game Mode. This is called once per player on the server. You can then add the player to your array there and mark the array as replicated so the other players know about it.
The game instance is accessible by all players, and does not need to be replicated. The death will be handled differently, so this isn’t really an issue.
I wouldn’t bother with all the premature optimizations you are doing with updating the HUD. It just makes the blueprints too complicated. The binding system is fine. It doesn’t matter if they are all ticking once per frame as that is only happening for each local client and that will be the least of your performance concerns latter on. If for some reason it becomes a bottleneck because you have an insane HUD, you can worry about it then… or just move the bindings to C++ if needed.
Yeah your probably right, I still have the mindset of “Every little thing matters, because performance in UE4 is terrible” from when I was working on my Terraria clone 5 months ago lol…