Daily Unreal Column #20 - Custom CMC
CMC (Character Movement Component) is a default component of the ACharacter class. Here is how you can replace the default class with your own subclass of that component.
Once you create your subclass of the ACharacter
class, let’s call it AMyCharacter
, you have add a declaration for a constructor function with the FObjectInitializer
parameter.
.
.
.
public:
AMyCharacter(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());
.
.
.
In the constructor’s definition, use the object initializer to replace the class used to create CMC.
AMyCharacter::AMyCharacter(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer.SetDefaultSubobjectClass<UMyMovementComponent>(
ACharacter::CharacterMovementComponentName))
{}
UMyMovementComponent
is a subclass of the UCharacterMovementComponent
.
Please note that the component we want to override must be overriden in all subsequent classes. Meaning that if we make AMyGreatCharacter
class that inherits from AMyCharacter
, it must also specify the component class overwrite.
One of the coolest components to work with ^^