Are non-capsule root components completely unsupported in UE4?

Note: I originally asked this question on the AnswerHub, but the forums might be a more appropriate place.

I’m totally new to the Unreal Engine way of things, but I do know that I’d like to make a 2.5D platformer game, and that I want to use a box for collision instead of a capsule due to literal edge cases (try walking off an edge in the side scroller tutorial; instead of falling, you’ll keep walking off the edge until the MyCharacterBP object runs out of curves to use to “stand up”).

After investigating the code a bit, I found that I would have to roll my own version of Character in order to replace the Capsule as a root component. Specifically, I copied and pasted the code, making a few adjustments here and there to account for the differences in the functionality between CapsuleComponents and BoxComponents. This initially caused a lot of issues with redefined code, which I solved by removing the offending code for now, but the current issue is that UE4 only seems to consider CapsuleComponents to be valid root components for actors. This seems really strange, but seems to be implied by the following lines of code in the engine:

LevelActor.cpp, line 667:


// currently just tests RootComponent.  @TODO FIXME should test all colliding components?  Cost/benefit?
UPrimitiveComponent* PrimComp = TestActor ? Cast<UPrimitiveComponent>(TestActor->GetRootComponent()) : NULL;

line 680:


// @TODO support more than just capsules for spawning, don't yet have - add primitive component function to calculate these, use boundingbox as fallback
UCapsuleComponent* Capsule = Cast<UCapsuleComponent>(PrimComp);

I’ve spent almost all of the free time I’ve had over the last two days just trying to get this class to compile with box collision. I wanna make sure I’m not barking up the totally wrong tree here. Should I be doing something entirely different to get what I want? (essentially, no ability for the character to stand just below and off of a ledge; either they’re standing on the ledge or they are falling off of it, like in every single other platformer)

When I attempt to Play In Editor with a Blueprint that is a child of a class that inherits from my CustomCharacter class instead of the default side-scroller subclass, I get an assertion failure on line 690 of LevelActor.cpp.

Edit: To clarify, this is the situation that will inevitably happen in a 2d platformer:

3d1ee95565448b1bd9453469641718818ef8e051.png

In that situation, one of two behaviors can be defined depending on the Perch Threshold. Either the character slips down and falls, or the character stands at that height and can continue walking onto the platform. What I want (and what I would get from a box component) is for the character to stand, but at the height of the platform, rather than the point of the curve where the capsule meets the edge. That way, when he continues to walk onto the platform, he doesn’t move upwards at all, because he never would’ve been standing below the edge in the first place.

Right now our Character movement logic only supports vertical capsules I’m afraid. We have discussed adding support for boxes, for exactly cases like this, but I’m afraid we have not had a chance to investigate further. If you manage to get it working, do consider submitting it to us as a Pull request, and we may be able to integrate it into the engine!

Just forked UE4 on Github. I’ll start working on that, and submit a pull request as soon as I have it done.

Found this archived AnswerHub postthat explores what it is I’m trying to do.

Can someone elaborate on some of the techniques they describe? It seems I can either create a subclass of UCapsuleComponent or override the necessary methods of UCharacterMovementComponent so they can cope with boxes.

Apparently, the main issue with box collision is dealing with corners during rotations, but that wouldn’t actually be an issue with a 2D/2.5D game because the only rotations, if any, would be 180 degrees. Corner rotations would essentially not be an issue.

As a small fix to allow ‘flat bottomed’ collision when walking on floors (so characters don’t look as if they walk down a slope before they fall of edges), I have just checked in a new feature “Use Flat Base For Floor Checks”, available in GitHub master branch (and in 4.2).

The fix is available here:

https://github.com/EpicGames/UnrealEngine/commit/2c79f299b9bc71ae3168199d01c6a237738e41a5

It’s odd that boxes aren’t used by default given the comment:



// @TODO support more than just capsules for spawning, don't yet have - add primitive component function to calculate these, use boundingbox as fallback
UCapsuleComponent* Capsule = Cast<UCapsuleComponent>(PrimComp);