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?
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!
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!
Hit Results under Cursor is more reliable, because it works even through HUD clicks.