How to add and remove a Box Collision Component in C++?

You have to create components in the constructor of your class.

It’s the same for all types of components.

 UBoxComponent* BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxCollision"));

This code will create a box component. Using the “Box Component” variable you can set all the variables like box extent, collision channel, etc in the following likes. For example:

Here’s a slightly more in depth tutorial explaining it:

https://docs.unrealengine.com/latest/INT/Programming/Tutorials/Components/1/

Cheers

As the following pic shows in BP, how to add and remove a Box Collision Component in C++:

100951-tttttt.png

Thx so much! that works for me.
Have a nice day!

I posted a article to show how to create BoxCollision and trigger callback of Overlap and Hit Event using C++.

1 Like