Dynamically change box collider extent to size of static mesh?

Hello,

I want to dynamically update the extent of a box collider in the construction script of a blueprint. I am using the “GetComponentBounds” method on the static mesh, and retrieve the “Box extent” from there.

I use this “Box extent” to update my Box-Collider component.

This works rather fine as long as I don’t rotate my actor. It seems as if the rotation of the actor (and therefore the rotation of its Static Mesh) is not really propagated to the box collider.

I now tried to apply the actors rotation to the box collider, but this does not work, and I assume this is because of a gimbal lock situation.

This is how I setup the Construction Script (just the part for the box collider update shown here):

As long as there is no rotation, everything is fine, the box collider aligns perfectly to the mesh:

But, as soon as I rotate around 90 degress around Z and afterwards around any other axis, it is broken:

I am pretty sure this has to do with a gimbal lock occurring here, but I have no idea how to fix this issue here … any help would be highly welcome!

Thank you!!

It seems I found the issue!

It is just necessary to update the “WorldRotation” of the Box Collider during the Construction Script. This is all - then it works magically :slight_smile:

I am honest, I don’t fully understand why it works this way, but I am happy it does :slight_smile:

How did you update this? Set world rotation based on what?