Blueprint Communication between Pawn and HUD

Sorry if this is a horrible question,
but I have been struggling to figure this out.

I know you can reference blueprints via variables and assign an instance of the blueprint but what about in this scenario…?
So, each player pawn automatically has a HUD assigned. I would like to store a reference to this HUD as a variable within the Character blueprint so I can access functions belonging to the HUD blueprint easily (such as… enabling/disabling HUD, updating it, etc.)

But how can I do this?
The instances are created dynamically at play-time so I cannot assign them physically via the level editor (not that I know of anyways).
Inside of the Character Pawn blueprint I attempt to: self reference -> get controller -> cast to PlayerController_C -> get HUD -> cast to HUD_C (but cast always fails here).
I can access the HUD but it takes me various inefficient steps that could cause trouble in the long-run (too much dependency). Currently I have to interact the PlayerPawn with the PlayerController to call Events/functions on the PlayerHUD. I want to get it so there is no middleman… directly call functions on the HUD from the PlayerPawn.

Sorry if I am not making sense or not realizing the obvious.
Any help or guidance is truly appreciated.
Many thanks in advance!

If this helps at all… its my current set-up. (functional)
Personally I think its inefficient which is why i am trying to improve it.

PlayerPawn:


PlayerController:


PlayerHUD:


PS:
I am new to blueprints… only about 2 weeks so cut me some slack! xD
From a programming perspective, I should be able to initiate / create a new instance of the object (blueprint) on the spot, shouldn’t I?
Is there no way to do this in blueprints? I feel stupid Dx

Get the playercontroller for the pawn (no need to cast) and pull from it and get HUD. You can then cast to this HUD if you wish to change varaibles inside the HUD bp. Hope this helps. :slight_smile:

I have somewhat the same question here, so I am not sure if this is the perfect way to do it. You might be able to follow along with my screenshots, but I will explain it in words too:

  1. Create a new Blueprint Interface (found under miscellaneous) called InterfaceHUD and create a new function ShowMessage with input message -> See screenshot 1
  2. Get the Event “ShowMessage” in your HUD and let it set the attribute (variable) message. Also add the InterfaceHUD to the hud via Blueprint Props -> See screenshot 2
  3. Change MyCharacter (or any other Blueprint) to call the ShowMessage function and give it any String input -> See screenshot 3

Did this help you to solve (a part of) your problem?

Well I don’t think I can do “get player controller” directly because it requires a ‘player index’ and what I am working on is multiplayer.
This is why I went with the casting method, which seems to work but I was trying to figure out a line of direct communication from the Player to the HUD without the Controller being the middleman.

So how can I know what ‘index’ the player is assigned to?
And if I go with the interface method, won’t it call it on all the instances of the blueprints that share that function?
So if there’s multiple players, won’t they all receive that “message”?

I believe the player index is only used for local games. It shouldnt a problem unless your allowing multiple players to play on the same machine. Another option is to add some nodes to the player controller BP that will get the pawn its controlling and pass a reference of the HUD it has to the pawn BP.

That would only fail if:

  1. You are attempting to get the HUD before it has been spawned ( highly unlikely)
  2. Your HUD class is not inheriting from HUD_C

If you really wish to not go through that sequence to get the HUD each time in the Pawn you could:

  1. OnBeginPlay - Call that sequence and assign the return of HUD to a variable
  2. Create a function to shorten it called “GetHUD” or whatever.

In reality you should be not be posting to the HUD from the Pawn. Your HUD should pull from the PController and Pawn in its Draw tick.