Custom character component classes

I have followed this wiki page and successfully gotten my custom character movement component class working.

Unfortunately I also want to change the default component class for the skeletal mesh to a custom one I have made.

In order to do this, I would need to change the constructor of my player class to tell it so, but there is no more room for any other arguments alongside the one that tells it to use the custom movement component class.

AVictoryPlayerCharacterBase::AVictoryPlayerCharacterBase(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer.SetDefaultSubobjectClass<UVictoryCharMoveComp>(ACharacter::CharacterMovementComponentName))
{

I got help from the unrealengine subreddit on reddit.com.

The answer is to chain the functions. Since Objectinitializer.SetDefaultSubobjectClass returns an Objectinitializer, you can then do the same thing to that one.

This leaves you with:

AVictoryPlayerCharacterBase::AVictoryPlayerCharacterBase(const FObjectInitializer& ObjectInitializer)
     : Super(ObjectInitializer.SetDefaultSubobjectClass<UVictoryCharMoveComp>(ACharacter::CharacterMovementComponentName).SetDefaultSubobjectClass<UVictorySkelMoveComp>(ACharacter::MeshComponentName))
 {
2 Likes

Thank you PersnicketyGareth! Exactly what I was looking for!

Needed to get a custom movement component and not spawn the mesh for my character. Brilliant! Only took 3 hours of searching and trying out stuff.