Right click on an actor

Hi!

I’m trying to implement OnClicked event for an actor but for the right mouse button. I didn’t find anything in unreal events and didn’t manage to create one. So I just want some basics: a player presses right button on an static mesh and a Print String function is called. Any help would be appreciated :slight_smile:

Thanks

Hey -

There are actually a couple of ways to setup a right mouse button click event. You can right click in the blueprint graph and directly add a “Right Mouse Button” event that will trigger when the right mouse button is either pressed or released. Alternatively, in the Edit->Project Settings menu under the Engine heading you can select Input. Here you can set up an action mapping for the right mouse button and give the mapping a unique name (ClickMe for example). Then in your blueprint add an event node for the ClickMe event. This method is preferred if the game is going to be for more than one system (“Press jump to jump” rather than “Press space to jump”).

Cheers

in the Edit->Project Settings menu under the Engine heading you can select Input. Here you can set up an action mapping for the right mouse button and give the mapping a unique name

I’ve already tried this but it didn’t help.


Maybe I need to somehow get an actor first?

In your screenshot you are using an axis mapping. What you want to use instead is the “Action Mappings” which is above Axis Mapping.

Okay, I’ve remapped right button click to actions.

And now the left click works but the right click still doesn’t.

The player controller does have a Right Mouse Button Event. Just get hit result under cursor for object.

Can you draw an example, please?

If you setup the “Action Mapping” like told you, you would need to make sure that the Input is enabled for that BP.

The CharacterBP should be enabled by default, but if you want other BP to accept rightclick you would need to enable it’s input:

http://puu.sh/cVMUT/e49a865792.png

But this is not what you want, because now you can just rightclick everywhere and it would print “Hello”.

So better get the Hitresult under Cursor and do your stuff depending on the hitresult. Here i just printed the Hitactors Name. Maybe you should also use a branch and plugin the “Return Value” which is just true or false depending on hitting something at all.

http://puu.sh/cVNbN/e25d117135.png

Thanks for your reply! I’ve finally managed to get desired functionality, but now I got the last question :slight_smile:

I’ve made an interaction according to your advice and now it looks like this:

Is there any other way to compare hit results? Now I just take the result and then compare it with the hardcoded string (Actor_Name_Blueprint). I wonder if it’s correct way to do so?

You want to compare one hit result with a second one? Make a variabel of type actor. Check with “Is Valid” if it’s NULL. If Is Valid is False, set the Hitresult Actor to this Variable. If it’s not NULL Compare the new result with the variable. After that, set the variable back to NULL.

No, I must have been misunderstood :slight_smile:

I have an actor in the level (a button) and I want to add right click event on this button. As far as I couldn’t find any simple solutions (like Event Actor On Clicked for the left mouse button click), I’ve made a solution as shown above. It works only if Hit Actor Display Name equals to the button name. So actually I asked if there is any other way to detect when right button is clicked only on particular actor (button in my example).

Hey -

The nodes “Event Actor Begin Cursor Over” and “Event Actor End Cursor Over” can be used to tell if the mouse cursor is currently overlapping the object (your button). Then you can use the a pair of branch nodes to check if the mouse is over the object and being pressed. The following image is for moving an object upward only when the mouse is clicking it but it shows the nodes you would use and how to set them up.

Hm ok.

So your button 100% needs to be clicked? You can make a Sphere Collider in the Button Blueprint and the OnOverlapBegin event could enable input. OnOverlapEnd would be used to disable input. This is just a sidenode.

Ok back to your problem. You should have a function inside your ButtonBP.

So try casting the Hit Actor to the Button Blueprint and from the return value of the cast, drag out the function and call it. It will call the function on the button you pressed.

Thank you !

Now I have a solution that suits my needs and looks very pretty :slight_smile:

Ok, i mark this question as resolved for you. In other questions please click the check mark at the left side of the answer to mark the questions as solved by yourself.

Hey,

I have been struggling with the same topic and I have the following solution that might be helpful to someone as well:

1 Like