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
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”).
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
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.
Thanks for your reply! I’ve finally managed to get desired functionality, but now I got the last question
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.
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).
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.
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.
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.