How to change root component of ACharacter?

The object inherited through: ACharacter (C++) → AMyObject (C++) → AMyObject_BP (Blueprint)

I want to change root component from CapsuleComponent to BoxComponent. My character is a flying vehicle. What can I do with it?

I tried next variants:

1. Change RootComonent in C++ from UCapsuleComponent to UBoxComponent in constructor.

Result: failed, implicit errors after launch editor and crash). (BoxComponent is UPROPERTY)

 BoxComponent = CreateDefaultSubobject<UBoxComponent>(ACharacter::CapsuleComponentName);
 ...
 RootComponent = BoxComponent;

**2. Set the capsule component sizes to minimal and create the new collision object in component list. **

Result: failed, new collision objects not responds collision (collision is setted up, physics, etc…) and vehicle overlaps the all.

Help please :slight_smile:

CharacterMovementComponent currently only accepts vertical capsules as the collision component.

The issue with boxes is that rotation is tricky, since corners may pass through objects between the start and end locations, since sweeps only support initial and end rotations, not sweeps through changes in rotation.

You may be able to extend the CharacterMovementComponent code to sweep something other than a capsule (possibly override MoveUpdatedComponent()) and modify the hit results as a result, but I think you’ll still have issues with rotation since we don’t check collision when rotation changes (not necessary for vertical capsule).

… this is the information I have on this subject. I know they were considering new shapes in a future release, but I haven’t heard when that would be.

If for some reason you still want to change a hierarchy of a character you can do the following in your derived class constructor:

	GetCapsuleComponent()->RemoveFromRoot();
	GetCapsuleComponent()->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform);

	USkeletalMeshComponent * mesh = GetMesh();
	mesh->DetachFromComponent(FDetachmentTransformRules::KeepWorldTransform);
	RootComponent = mesh;