Static Mesh with multiple collision boxes

So I’m guessing I’m probably approaching this problem from the wrong angle, because I cant find any kind of reference to this. But I noticed that when you add collision boxes to a static mesh, you can add a Name to it. I had assumed this is so that you can detect which box the user has clicked on. I’m trying to do this so that I have specific locations for the user to click on a static mesh.
However I cant seem to figure out which box the vector collided with, the click event just identifies the actor from the player controller. I’m looking through all the ClickedPrimitive parameters and the HitResult components but cant find any references to which box received the hit.
Any ideas of a better way to do this?
Thanks.

I hope it works :slight_smile: Please follow up with the results :smiley:

Hi,

When you speak about adding collision boxes to a static mesh, are you strictly speaking within the static mesh editor? In general, my approach would be to create an Actor Blueprint, with this static mesh. Then, add whichever box, or other shape, collision components and position them as necessary.

By doing this, you can see from Hit Results the Hit Component, and it should return the specified collision component hit; and when it comes to overlap/hit events, the returned actor component should be what you need.

I hope this information helps, but if it doesn’t, please provide more information (preferably images) of what you are currently doing and what you are trying to achieve. Good luck :slight_smile:

Oh yes, I added the collision boxes using the static mesh editor. But yeah I think your approach is the correct one, I will try that.

Thanks!

Ok, so I created the blueprint with my static actor and 3 collision box components. However the HitResult is returning the static mesh actor still, I can see the 3 component children from the PrimitiveComponent… but still I dont know how to tell which collision component was hit. Any ideas?

Wow this is great! thank you very much. I can definitely use this for my project… I was actually doing the code In C++ so I think this is much easier.

You can do the following to determine which one was hit:

I created a test case scenario using the First Person Template in version 4.26.2 where I have the projectile hit an actor and return the component that it hit. Here is what I did.

  1. I created a new Blueprint Actor called TestCollision that contains a cube static mesh and three box collision components. This is how they are set up visually with each other.

  1. The cube static mesh is set to have No Collision.

350711-cubemeshcollision.png

  1. The three box collision components have the following collision settings:

  1. Then I added a print string that would display the name of the Other Comp returned from the Event Hit inside of the FirstPersonProjectile Blueprint:

350713-eventhit.png

  1. Then, I placed the TestCollision actor in the world and used play-in-editor with the following result, I will also add the print string from the log in case they are hard to see in the gif:

350714-example.gif

Here are the print string logs found in the Output Log:

LogBlueprintUserMessages: [FirstPersonProjectile_C_7] TestCollision_2.Box
LogBlueprintUserMessages: [FirstPersonProjectile_C_8] TestCollision_2.Box1
LogBlueprintUserMessages: [FirstPersonProjectile_C_9] TestCollision_2.Box2
LogBlueprintUserMessages: [FirstPersonProjectile_C_10] TestCollision_2.Box1
LogBlueprintUserMessages: [FirstPersonProjectile_C_11] TestCollision_2.Box1

As you can see, the returned component is telling me the different Box components from my actor.

I hope this information helps, but if it doesn’t, then we can keep debugging :slight_smile: