Clicking on different actors (ActorOnClicked, or Hit Results under Cursor


I’m trying to click on an actor, and when the actor is clicked on they get a little widget around them and a health bar pops up on screen for enemies or a chat box pops up for a quest giver for example, and then when you click off of them it removes the little widget saying they’re selected.

I had it working for the enemy to some extent with Get Hit Result Under Cursor by Channel, though it was very inaccurate and I couldn’t click it off. Once I tried adding the quest giver to the mix, it wouldn’t work properly, I had a right click event set up for each of them, in my blueprint.

So after much stress, I’ve tried moving to ActorOnClicked. This works for the first click but refuses to fire again. (I had to swap right click to movement from targeting and left click to targeting from movement to try this, which isn’t what I wanted, as I couldn’t find an alternate such as ActorOnRightClicked.)

As a test I set ActorOnClicked to just print hello, and it will only do it once.

Am I missing something with this or is it not working correctly?



Just to make sure you are starting off on the right foot, on your PlayerController, Under Class Defaults: Mouse Interface: do you have the following enabled: Enable Click Events, Enable Mouse Over Events. Also keep note of what Default Click Trace Channel is set to, though you can always get hit results under cursor for other channels so it shouldn’t matter atm.

First off to help with making it easier to click on an actor of any sort, you can add a collider to the actor and set it to a much bigger size than the actors mesh it’s self so its easier to click, set its collision so overlap events are on, Collision Presets is set to Custom, Collision Enabled is set to Query Only, all collision responses are set to ignore expect for the Trace Responses channel you want to use, have that set to blocked. If you want you can set up your own channel for clickable objects by going into the project settings: Engine: Collision: Trace Channels, and clicking New Trace Channel. I suggest you set the Default Response for it to ignore as well. Then you can use that channel when you do Get Hit Result Under Cursor by Channel.

Yeah I made sure they were set, whats odd is it fires once with the ActorOnClicked event, but never again.

The trace was sort working before with the trace channel to select one. But it would only work when a single one was setup to be clicked, and I couldn’t “click off” them.

The trace channel is set to visibility on the player controller. I’ve not really looked into all the different bits as I’m quite new and very self taught.

Do you know a way of differentiating between the hit actor? So if it’s one it does one thing, another does something else, neither does something else again?

Thank you.

Okay, I’ll have a look at trying to reproduce that and get back to you. Hopefully I can get it to work. Thank you!

  • One thing that will help make this all work a bit more smoothly is if you know how to make & use Blueprint Interfaces. I would set up a blueprint interface for clickable objects, and set up an event for Clicked that passes a bool for if it was clicked on or clicked off of. You can add the interface class to an actor by going to it’s Class Settings: Interfaces: Add & selecting the interface you created.
  • This way no mater what the object is as long as it has this interface class on it all you have to do is call the Clicked interface function on it and pass true or false. Then have that class implement the logic it wants to do when that event is fired and have it do what it needs to depending on the passed in bool value.
  • So in your player controller what I would do is:
    1.) Create a variable for actor reference for last clicked.
    2.) When ever you click, left or right which ever is your preference, do a Get Hit Result Under Cursor by Channel for the channel you want to use.
    3.) Break the hit results, if hit actor is not valid but your saved actor reference is then on the saved reference call the interface function for Clicked and pass in false and set the reference to nothing to clear it.
    4.) If the hit result actor is valid, check to see if it equals the saved reference, if it does then do nothing.
    5.) If the hit result actor is valid and it doesn’t equal your currently saved reference & the saved reference is valid, call the interface function Clicked and pass in false on the saved reference. Then call the interface function Clicked on the Hit result actor and pass True, then save that actor as the new saved reference.
    6.) If the hit result actor is valid and it doesn’t equal your currently saved reference but the saved reference is NOT valid, just call the interface function Clicked on the hit result actor and pass True, then save that actor as the new reference.

Sorry I forgot a condition, if the hit result is not valid and the saved reference is also not valid then do nothing.

Brilliant thank you, that seems to have most of it working now, I can select and unselect both actors. I have a little more editing to do to get the last few bits working with it. But you got it to do exactly what I wanted!

Thanks again!

Hit Results under Cursor is more reliable, because it works even through HUD clicks.
More here