How to get the last clicked on actor ?

I need to get the last clicked on actor in the hud blueprint without having a cast loop.
(UE 4.7 preview 7)

Just create a “LastClickedOn” variable of type Actor in your HUD blueprint, and whenever you click on something (I assume in your Player Controller), assign that actor to your LastClickedOn variable in your HUD BP.

Not sure what you mean by not having a cast loop. You’re talking about your HUD BP and not a UMG widget, right?

So i’m trying to create a strategy game in which you can select a ‘soldier’ by clicking on it, but i need some info of it displayed of it in the hud (health, type, …). What i would like is that the hud look itself (or the player controller or gamemode) if something gets clicked on, checks if it’s a ‘soldier’ and then gets info from it and displays it.
The ‘soldier’ is a pawn and the hud is a blueprint (based on the hud class).

BTW what i first did was when the ‘soldier’ got clicked on send the info to the HUD and set the ‘soldier - variable’ there to that ‘soldier’ which got me into a casting loop. Currently i have thesame but now the ‘soldier’ sets the specific variables (type, health, …) to display in the hud. But i would like it as described above.

BTW this would also make it easier to send commands to the actor, like go there, then i already have a reference to it.

So by casting loop you mean circular references?

The way I get around that in my project is by only directly referencing “one-way”, and using a Blueprint Interface.

So basically if you have your HUD class (which is used to spawn the UMG UI and communicate stuff to it), the UMG UI (which displays the actual info), and the Player Controller:

  1. Create a Blueprint Interface named “UI Interface” or something.

  2. In that interface, create a function with whatever inputs you need to give your HUD/UI (soldier health etc). Let’s call it “Display Soldier Info” for this example.

  3. Assign that Interface to your HUD and UMG UI (in the Blueprint Props/Class Defaults, depending on your engine version).

  4. When you click on a soldier in your Player Controller, pass a reference to that soldier to your HUD class.

  5. Have your HUD check if it’s a soldier and if so, get its infos.

  6. Have your HUD send an Interface message to your UMG UI. If you drag off your UMG UI reference and type “Display Soldier Info”, you should see a “Display Solder Info (Message)” option. That is what you want to use.

  7. In your UMG UI, create an “Event Display Soldier Info” node. That is what will get called when the HUD sends the message in Step 6.

The Blueprint interface basically acts as a barrier between your UMG UI and your HUD so that you do not run into circular references. In this example, the UMG UI will be “allowed” to reference other blueprints directly, but every other blueprint should go through your HUD class to call anything in your UMG UI, and that HUD class should only use Interface calls.

But you could do it the other way around too (Your UMG UI is the one using only Interface calls and never referencing anything directly, and everything else can reference your UMG UI directly).

That would help but i need to get a reference or something like that to the ‘soldier’ in the hud blueprint so i can call functions of it, like “GoThere” after right clicking somewhere on the map or things like that.

I got it, i sort of did as JParent said: when the soldier gets clicked it sends a reference of itself to the playercontroller. When the hud needs to be drawn it gets a reference to a soldier from the player controller and gets all the data from that. Thx :slight_smile: