How to use "OnClicked" node?
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.
asked Aug 28 '17 at 10:38 AM in Blueprint Scripting
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:
the content of my BP Interface looks like this:
really simple and will do the job.
Now, here comes the more complicated part. In your case, this is for the ThirdPersonCharacter Blueprint.
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:
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.
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.
Now some necessary prep work. Inside the Actor Blueprint, you go to Class Settings and add the Blueprint Interface you made.
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.
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.
Follow this question
Once you sign in you will be able to subscribe for any updates here