Spline collisions in Unreal
[ue4
]
A spline component in Unreal Engine doesn’t really provide any collision detection, as far as I can tell. You can use the spline to add spline mesh components to an actor and those can in turn have collision, but I ran into a use case where I wanted essentially a spline based volume for detecting overlaps. So, rather than adding spline mesh components to the actor I simply added Box collision components - this gave me the results I wanted.
BP_SplineCollider
I created a Blueprint Actor called BP_SplineCollider, added a SplineComponent to it and added the following construction script:
The first part works out how many samples I want to take along the spline - I want it to be approximately once per meter, adjusted to the length of the spline.
The second part calculates the center point between two samples, and a rotator that is oriented along the spline at that point.
Finally, I set the extent of the box, enlarging it a bit to ensure coverage through the twists and turns.
The result
I can now add the spline collider to a scene, and as I edit the spline, it gets collision boxes added around it.
The ActorBeginOverlap event now gets properly triggered if I walk through the spline - mission accomplished!