Best way to add collision boxes to a custom component?

Hi,

I want to add a collision box as a variable for a custom component (let’s call this ColliderComponent), which can then be reused in different actors. Somehow creating a Collision Box variable in the component blueprint and setting it as ‘Editable’ still doesn’t allow me to actually draw a collision box in the actor containing the ColliderComponent and set the component variable to the one in the actor.

What’s the best way to perform this functionality?

If you add a box collision to a blueprint actor, you should have it available to edit the component on placed instances as well as having access to its default settings directly in the blueprint editor. If you’re not seeing it, perhaps it needs you to show collisions in the editor (“alt-C” I believe).

If you’re trying to make a single actor with just a collision that you can spawn/attach/adjust in code, you just need to cast to it. If you want the level designer to edit those things, exposing the variables to be public is correct, but make sure that you’re not trying to adjust the component on the placed actor, rather you’re actually changing your public variables. Giving them especially unique names helps with that.

If you want it to be properly editable, make sure you apply the variable changes in the construction script so everything updates as you change them. You can adjust box extents and its position/rotation/scale, there are nodes for those.

Thanks for the quick reply! However, I think I didn’t phrase my question correctly.

The problem lies when I want to add a Box/Sphere/Capsule Collision variable to a custom Actor Component.

Heres an example of the variable I want to add:

Later, I want to set this variable to a Box/Sphere/Capsule Collision in the parent actor I attach the component to. Like this:

Hi,

did you ever figure this out? I’m trying to achieve the same thing at the moment and am stuck…

Gosh, it’s been a while since then…I honestly can’t remember. I haven’t worked with UE4 in a long while too. Sorry that I can’t help!

No worries and thank you for the prompt reply!

Even though I still don’t know how to get a trigger box or box collision (or similar) functioning in a custom component by adding it as a variable I have found a work-around, so in case anyone else is facing the same challenge, here’s what I did:

  1. create a separate actor blueprint containing only a box collision, does not need to be in the scene.
  2. in the custom component, spawn that actor at ‘begin play’
  3. out of the ‘return value’ of the ‘spawn’ node, ‘get’ the variable containing the box collision (type the name of the box collision)
  4. then manipulate it in the custom component to the size/location etc you need
  5. drag off of the the extracted variable (step 3) and assign a custom event to ‘onComponentbeginOverlap’ of that variable (box collision)
  6. use that event to trigger the action that you want the custom component to perform.

Still interested in how to set up a collision trigger purely inside a custom component, but I’ll carry on with this solution for now.

Cheers