Download

How can I change UCharacter's root component before construction?

I’m trying to add support for UBoxComponent as the RootComponent of UCharacter. However, the constructor assumes it already knows what type of collision object it is. Ideally, users will be able to define what type of collision is used in their subclass of UCharacter, but the problem is, UCharacter essentially needs to know what that type is before, say, MyCharacter is able to tell it. Is there a way to do this without making massive changes in UCharacter’s code? I was hoping to write this modification in a way that Epic might actually add to the engine, since it will improve every single platformer game.

Currently our Character class only works with a capsule as collision. There are several assumptions in the CharacterMovementComponent code that assume this. We are looking at adding an option for also supporting box-like collision as well though, so you have a flat bottom.

In other cases if you want to change the class of a component, you can use syntax like this in your derived class constructor:



AMyCharacter::AMyCharacter(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP.SetDefaultSubobjectClass<UMyCharacterMovementComp>(ACharacter::CharacterMovementComponentName))
{
...


You use the name given to the component when it was created in the parent class to identify which one to change.