x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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!

Product Version: UE 4.14
Tags:
more ▼

asked Aug 28 '17 at 10:38 AM in Blueprint Scripting

avatar image

raining chicken
12 1 3 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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:

alt text

the content of my BP Interface looks like this:

alt text

really simple and will do the job.

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

alt text

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:

alt text

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.

alt text

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.

alt text

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

alt text

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.

alt text

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.

more ▼

answered Aug 29 '17 at 04:56 AM

avatar image

Aphermion
236 3 6 7

avatar image raining chicken Aug 29 '17 at 05:43 AM

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.

avatar image raining chicken Aug 29 '17 at 10:31 AM

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! :)

avatar image Aphermion Aug 29 '17 at 04:55 PM

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

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.

alt text

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.

alt text

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.

avatar image raining chicken Aug 30 '17 at 04:36 AM

it's working, thank you very much!! :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question