Help with component line trace?

Hey all,

So I’ve got a Blueprint named BP_Rockslide that is made up of 12 “Boulder” static meshes. I want the player to be able to shoot each mesh and destroy them individually but I’m having difficulty figuring out how to trigger the “Hit” action to lower the health of each boulder when they’re shot.

I’ve set up a line trace by channel on my player pawn and if it detects that the hit actor is implementing the correct interface, it sets the Hit Component as a variable and then this is where I get lost. I don’t know how to pass this info over to the BP_Rockslide blueprint and then tell it which boulder was hit so I can take off health.

Here’s my code so far:

Pawn Event Graph:

BP_Rockslide Event Graph:

The problem I’m having is that I don’t know how to call my custom events “HitBoulder01”, “HitBoulder02” etc. Basically I know that I need to set it up so it says something along the lines of "If Component name = “Boulder01” then run the code for “HitBoulder01” but I have no idea how to do this. I can get the Display name of the component but this changes if there’s multiple instances of the BP_Rockslide in the level and I’m also not sure how I can use that info to trigger the various component code.

Also I’d like the be able to have multiple different blueprints that do something different when their component is hit so right now it’s a rock slide, but I’d also like to have something else that the player interacts with (RE shoots) in the future and have that do something different based on the hit component so I’d rather not do the specific checking inside the pawn. I’d rather be able to take the hit component, and then handle the code depending on the BP inside the BP itself. I don’t know if I can use an interface for this or not? Interfaces still confuse me.

That’s a weird design (from my point of view). Is there a reason why you didn’t implemented a BP_Boulder or something instead of putting all of them in one single BP?
That way, you could have a base BP_Boulder, with a mesh component, collisions, … , and you would be able to avoid code duplication and able to create child BPs with different behaviors: sliding, interactive, pickup, …

Apologies, I didn’t make a BP_Boulder. There’s a BP_Rockslide with 12 boulder meshes in it. I was really tired when I posted this so maybe I wrote something wrong?

Maybe this (not pretty but it works):

You have your BP_Rockslide with 12 boulders (static meshes). In my case, just 2 boulders.
1 - You create a function (HittedBoulder) with 1 parameter of the type “Mesh Component” that will be called by the trace hit result.
2 - You check which one of the boulders was hitted by comparing each boulder to the parameter and do your ops on it accordingly (in my case just print the name of the boulder: Boulder_1 or Boulder_2):

In your player, the hit result should be something like this:

Thanks for the help EvilCleric,

The problem with implementing it in a way like that is that it’s not re-useable because you’re casting specifically to the BP_Rockslide off of the line trace. I eventually want to have a dozen different “Threats” like “BP_Rockslide”, “BP_Fire”, “BP_Whatever” and then be able to have the player simply “Interact” with all of them and get “solve” the problem.

After a good night’s sleep (and a refresher on how to use interfaces) I was able to look at it with fresh eyes and figure out a solution. Thanks so much for your help though :slight_smile:

Ok I figured it out. For anyone else trying to figure out how to get the specific component of a blueprint and do something with it, here’s how I handled it:

Firstly in your blueprint that contains all of the components, make sure that you give each one a distinctive unique name. In my case since there’s a dozen “Boulders” I’ve simply named them Boulder01 - 12

Next create an interface and name it after the object type you’re interacting with. In my case I’m interacting with “Threats” which is a name specific to my game so I named the interface “BPI_Threat” and then I added the interface to my “BP_Rockslide” blueprint in the Class Settings. Inside the Interface, create a function called PlayerInteractWithXYZ where XYZ is the name of your object type so for me it’s “PlayerInteractWithThreat”, then give it an input of “Actor Component” and name this “HitComponent”. Finally give the category a name like “Assorted YOURGAMENAME” that way it will show up at the top of the list when you look for it which makes it easier to find. I’ll explain this in a bit.

Over in your pawn (or wherever the line trace is happening) from the Break Hit Result node, drag out from the Hit Actor pin and type “implement” and pick the “Does Implement Interface” node. Add a branch and plug the return value of the Does Implement Interface node into the condition. Next right click in empty space and type “Player Interact With” and you’ll get your custom function from your interface with (Message) added to the end. Choose this node and for the target, plug in the “Hit Actor” from your Break Hit Result and for the “Hit Component”, plug in the “Hit Component” from the Break Hit Result. Compile and save.

Inside your blueprint that contains all of the components (in my case BP_Rockslide) right click in the event graph and expand the “Add Event” category and then your “AssortedGAMENAME” category and you’ll see an “EVENT Player Interact with XYZ” for you to choose. From this you can now drag off of your “Hit Component” pin and type “Get Object Name”. Don’t use display name as this is completely unique to each and every instance you place in the world. Now that you have the object name you can run your own unique code depending on which object name is returned. For example you could drag off of the Return Value from the Object name and then type == and use the (Equal String) node to check if it’s name is “Boulder01” like in my example and then connect the result into a branch. If it’s true, run a custom event like mine “HitBoulder01” to remove health. If not, check to see if the string is == to another one of your component names.

​​​​​​​