Passing characteristic of Pawn to HUD on select

Hi,

I am currently working on a little village builder/management project. Currently from following tutorials I have a basic ‘grunt’ pawn set up with AI controller and a basic wander task in behaviour tree, and an RTS style camera with the ability to ‘select’ the grunt, displaying a decal around his feet.

For my next step, I want to add a ‘Hunger’ variable to the grunt pawn, which will decrement over time, and whose level can be displayed on the HUD when that is selected.

I’m confused about how to go about setting this up. Eventually I will want the ‘Hunger’ level to trigger a ‘go find food task’ in the Behaviour tree/AI controller, so my first thought was to put it in the pawn’s blackboard. But researching this it seems difficult to decrement variables in the Character blackboard via his event graph?

Short question:
Where should I store the Hunger variable, to best be able to decrement/set it via events? Pawn’s event graph? AI controller? Blackboard? Also, how would I go about drawing this value to a UMG widget when that pawn is selected?

I’m a bit lost, any help appreciated - even to point in the right direction.

I attached the select function from the RTS camera blueprint, can add any others if it helps.

Thanks for any help!

In to Pawn obviuesly. I recomand you to have Selected Actor in PlayerController, from HUD you can access the controller which HUD belongs to and from there you can access Selected Actor. In UMG you can access controller ot from “Get Owning Player”

I also gonna ask you this since i notice you using casting and interfaces at same time. You are aware that you can call function direly in to object without need of interfaces? just drug object pin from cast and drop it in empty space and there search for function inside the object.

Ah yeah it seems simple now after I’ve done it. Thanks for the reply, very new to UE4. Now have the Hunger variable set up and decrementing on Delta tick (not the most efficient I’m sure especially when there will be many pawns but it will do for now).

Didn’t know that about casting and interfaces either, I thought you needed the Interface from the tutorials I watched! Thanks again.

So next dumb question: how will I add the Selected Actor to Player Controller? At the moment I have no custom Player Controller or even Game Mode set up - I just have my RTS Cam set to get possessed by ‘Player Controller 0’ on Event Begin Play it’s been working so far with being able to click on the guys… I’ll have more time tomorrow to look into Game Mode/Setting Up Custom Player Controller (I’m guessing these two are what I need).

Cheers

Just make blueprint from PlayerController and set it in ProjectSettings as default PlayerController

Ok so I updated the Camera Pawn thanks to your advice. It now sets a Selected Actor variable in the Player Controller.

I think that’s what you meant?

I’m confused by the next part in your answer though:

“from HUD you can access the controller which HUD belongs to and from there you can access Selected Actor.”

You can assign a HUD to a PlayerController?

ATM trying to Draw the widget I made both in the HUD I wrote or in Camera Pawn not working for me <-nvm this, I had no Add to Viewport node

Like I thought something like this would work

but no joy.

Can you elaborate a bit about interaction of the custom Player Contorller with HUD/Widget? Cheers

Edit: Had not put Add to Viewport after Widget -.- (need to stop trying this stuff late at night) it’s now drawing the widget. I’ll come back to it tomorrow and try get the values and everything linked up, if I have any more trouble I’ll ask or if not will mark as answered.