Download

Get blueprint on trace hit?

Greetings,

I’m trying to add some functionality to my game that would make it so when I look at an object, it’s material temporarily changes and some text appears inside of it until I stop looking at it. I’m currently trying to achieve this using a trace + blueprint interface. I’m sending an event to my object when the trace hits it.

Is there some way to check what blueprint an actor/component is using when a trace hits it? or some other way? Ideally i’d like my trace to send a message to whatever object its hitting, rather than having to call out the specific blueprint I want to send the message to.

I’m also open to other ideas on how to accomplish this, if anyone has any suggestions.

Thanks!

Guess no one has any ideas on this?

Anyone know if it would be possible to write a custom node that finds the blueprint that an object belongs to?

I’m not entirely sure if this is what you want, but if you want something to happen when your trace hits a specific actor (blueprint), you can cast the actor you hit to the specific blueprint you’re looking out for. If the cast succeeds, then that means you hit that specific blueprint. I can give you an example if you want.

Using an Interface Message definitely sounds like the right approach for what you want. I’m not a hundred percent clear on what specifically you need, though. You can send an Interface Message to whatever actor the trace hits without needing to know what type of actor or Blueprint it is specifically, which is one of the main advantage of Blueprint Interfaces. If the target of the Interface Message implements the matching Interface Event/Function then it works, and if not, then nothing will happen.

One thing that might help is the “Does implement inteface” node. I’m guessing you’re getting the hit result from your trace to figure out what actor was hit, and then sending the Interface Message to that actor? An extra step you can add would be to drag off that actor reference and try the “Does implement interface” check, which basically will check whether the actor contains a specific Interface Event and return a bool. That way the Blueprint that’s doing the trace can use that information to display a button prompt when the trace is hitting something valid, or whatever else it is you might need to do.

I guess it must just be my general confusion on blueprint interfaces, no matter what I tried I could never get my two blueprints to communicate unless they specifically called each other out. I’d love to see an extremely simple tutorial on passing a bool from one object to another.

In this video I cast the thing that touches the pickup to a Character, so I can then make changes to it:
http://youtu.be/q_9QKzLK-sU

I do want to make a video tutorial that explains how to do basic ‘interaction’ traces with the world as you describe. Hopefully this week!

Thanks for the link James! I believe that tutorial is a class blueprint communicating with a level blueprint? I’m trying to achieve something using two class blueprints… I still haven’t managed to figure it out, but I haven’t had much time to poke at it.

The super simple version of what im trying to do is:

Player sends out a trace that hits object > object detects that it was hit and changes its material > player stops looking at target > object reverts back to default material.

I was able to achieve the effect with a blueprint interface, but it toggled the material of all instances of that blueprint. I’d like to be able to have it only change the material (or do whatever) when the specific actor is hit.

A basic trace interaction tutorial would be awesome, thanks for your help!

I made a video that shows a case quite like this, hopefully we’ll get it up soon! One thing you will need to add is having the player remember what wall they were last looking at, so they can call an event to set it back when they look away.

EDIT: Wrote this before JamesG made his post. James, I literally can’t wait until that video of yours gets up, I have been wondering about this all weekend!

Hi venain,

Let’s help each other out! I was looking to do something like you were - making it so when the player looks at an object, something happens. I’ve gotten pretty far in it at the moment - the functionality works, but for some reason, the function continues to happen over and over again. So, as a warning, what I’m about to tell you SORT of works.

The main difference is that this method will not be telling you to send something to a blueprint, instead, it will be telling you to send it to an actor.

First off, I set this up to be a function on my character, which is how I got the input/output nodes. I named the function, “Observe Actor”. Then, I edited the function and put in all of this good stuff that you’ll see below:

Next, on your character blueprint, put the following in:

I won’t go too much into BPI, since I’m assuming you know how to set that up already. What this will do is that it will call the event On Observed on that specific actor that you’re looking at, and not at it’s blueprint.

Like I said up above, this isn’t perfect, and I’m still in the process of making it better. I have a method of making it check to see if it’s not being looked at anymore, but then what ends up happening is the event is run over and over again still for some reason. But hopefully the above will at least get you into the right place of talking to an individual actor and not the blueprint.

Thanks for the info McSean! Thanks to your post I was able to get the behavior I wanted. I think my entire problem was that I was using a single line trace, changing to a multiline trace fixed everything. As for the problem with it spamming the “not being hit anymore” state, in my case its because the trace is setting the bool every frame, so when you aren’t looking at something, its just spam sending that result.

I was able to solve this using a switch and two “do-once” nodes. This may or may not work depending on what info you’re sending from your character, but this solution should solve most issues. I’ve included a picture the tail end of my trace graph (located on my player) and the graph that controls what happens when an object is hit (located on the object). The second picture is showing the flow of what happens when the object is hit by the trace, to make the whole do-once loop more clear.

Sender Blueprint

Reciever Blueprint

And thank you for the info, Venain! I slapped my forehead when I saw your receiver blueprint, I was doing all of this convoluted things with an entirely separate function when a simple boolean would’ve worked. Again, thanks for the help!

Although I had solved this enough to be passable, I spent a bunch of time last night building it from scratch in a much more efficient way. The scenario that was causing me a lot of problems is this:

Object A and Object B are right next to each other. You look at object A, and your expected behavior happens (material change, etc). You then go straight to looking at object B without your trace hitting anything in between them. Object A still thinks you’re looking at it because technically, the trace is still hitting a valid target.

The way I had originally solved this was by having every single interactable object checking (every frame!) to see what object the player was hitting and comparing it to themselves. This could get extremely expensive with a scene full of interactables.

The solution I came up with last night is a lot cleaner and hopefully faster and less resource intensive. Below are links to the graphs (2 graphs, one sender and one receiver). The comments should explain everything clearly (I hope) but feel free to ask any questions!

Receiver:

https://dl.dropboxusercontent.com/u/2348343/BluePrints/TraceInteract01.jpg

Sender:

https://dl.dropboxusercontent.com/u/2348343/BluePrints/TraceInteract02.jpg

https://dl.dropboxusercontent.com/u/2348343/BluePrints/TraceInteract03.jpg

https://dl.dropboxusercontent.com/u/2348343/BluePrints/TraceInteract04.jpg