How to use "OnClicked" node?

Hello,

I’m not quite sure whether the “OnClicked” node is the right type of node I should be using for this but basically what I need is to know is how to make a matinee play when I click a specific object in the third person template. For example, if there was a cupboard drawer I would aim my crosshair at the drawer then left click on the drawer to play the matinee of it opening, then also have a reverse version to close the draw vice versa.

Thanks!

This will be a long post, so bear with me.

(Also, I don’t know how experienced you are, so I will explain this like you’ve never done this before)

Here is what I did in my project:

This step is essential to make my approach work.
To make the communication between blueprints easier, I made a Blueprint Interface, you can find it in there:

http://i.imgur.com/wl56Rxi.png

the content of my BP Interface looks like this:

http://i.imgur.com/XZiOSlU.png

really simple and will do the job.

Now, here comes the more complicated part. In your case, this is for the ThirdPersonCharacter Blueprint.

http://i.imgur.com/QJtJz2L.png

This will draw a line from your characters head, to the mesh/actor you are looking at with your camera.
I’ll walk you through this, since you’ll probably need to modify it a little.

So first we get a reference to the Character Mesh, then we get its world location. Now we need to add a bit to this vectors Z axis value, since we need the location of the head. This is what the macro “MakeLineOfSightVec” does in my example (the name is a bit off, since I used it for something different before).
You will need to replace this macro with something like this:

http://i.imgur.com/XPmgl7b.png

So you break the vector of GetWorldLocation and add to the Z value.
Now, how much you need to add to Z depends on how tall your character is, you’ll probably need to play around with it. Then you make it a vector again and plug the result into the Start of LineTraceByChannel.

Next we need to figure out where the player is looking. For that, we get a reference of the Camera. (I named mine after the camera in the 3rd Person Template, so yours should also be called Follow Camera.) We plug the Reference into a GetForwardVector and multiply it by a float. This float determines the range, so how far the line will be drawn.
The result of this multiplication will be added to the result of your Make Vector. The sum needs to be plugged into the End of LineTraceByChannel.
The whole LineTraceByChannel gets executed by the EventTick Event.

A little note here. If LineTraceByChannel doesn’t get you the results you want, you could also use LineTraceForObjects. With that, you can look for specific types of objects.

http://i.imgur.com/hTZNKnG.png

Back to where we were. To know which actor we’re looking at, we need to Break Hit Result. Since we’re only looking for Actors we can interact with, we need to filter a little. So we plug the Hit Actor into Does Implement Interface, and select the Blueprint Interface we created in the beginning.

Now we can use this with a button. If you want to use the mouse click, you should create a new binding for that in your Project Settings.
This InputAction now goes into an If Branch, since we only want to be able to activate the actor if we’re looking at it.
Therefore, we plug the Return Value of “Does Implement Interface” and the Return Value of “LineTraceByChannel” into an AND, which will serve as the condition for our If Branch.
If the condition is True, we fire our Function Message. To create this node, just search for the name of the function that is inside the Blueprint Interface you created in the beginning.

AAAAnd that’s it for the Character Blueprint.

Now, we need to make the targeted actor actually do something when triggered.

To do this, we need to create a new Blueprint Actor.
Preferably, you right click the mesh you want as your actor in your Content Browser, and create a blueprint from this.

http://i.imgur.com/gyDcEyY.png

Now some necessary prep work.
Inside the Actor Blueprint, you go to Class Settings and add the Blueprint Interface you made.

http://i.imgur.com/rmok9EN.png

This will allow you, to use the Event we need.

If you right click → add event, you should be able to see an Event for the Blueprint Interface.

http://i.imgur.com/Euq47cJ.png

This event will be fired, when the If Branch in our Character Blueprint is True.

Now you can start your Matinee with this Event (or whatever you want the actor to do).

Phew, that was a long one, I hope this will help you out.

Thank you very much for your time, really appreciate it! I’ll try to finish this as soon as possible and give you the results, although it may take me a while.

So I’ve managed do everything and so far it’s working! I hope I’m not asking for too much but, how do I actually get the Matinee to play using the Event Interact Func? (Sorry, not very experienced with this kind of thing)

Really appreciating the work, thank you! :slight_smile:

I use UE 4.17, Matinees have been kinda replaced by the Sequencer. So I’m no Matinee expert.

http://i.imgur.com/j0rOcLU.png

I’d just make a flip flop (this switches between the two different Exec every time you press the mouse button) and play or reverse the Matinee. So if you trigger for example a door, it opens. If you trigger it again, it closes.

http://i.imgur.com/3q3yodr.png

Now, how you get the reference to a Matinee Actor is something you’ll have to look up, I’m sure there are plenty of tutorial videos on youtube for that. I mean, technically you could “get all actors of class” on BeginPlay, but if you have multiple matinee actors you’d have to get the one with the correct index.

http://i.imgur.com/xx8ANN4.png

I use animations for stuff like that, so no external reference involved and animations can be used outside the level. Matinees are saved inside the level, as far as I know.
Of course, this requires a rigged Model.

it’s working, thank you very much!! :slight_smile: