Download

Custom Character Movement Component only works when unreal is restarted

Hello! I was trying to use a custom Character Movement Component in a custom Character without any success until I finally found what was going on. After compiling the code, the blueprints that inherited from my CustomCharacter, which should have a CustomCharacterMovementComponent, still used a regular CharacterMovementComponent. I then closed and restarted the engine and voilà, now CustomCharacterMovementComponent was being used. Is there something I am missing? This behavior seemed quite strange to me and I thought that other people might stumble on that.

CustomCharacter.h and .cpp





#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "MyCharacter.generated.h"

UCLASS()
class MYPROJECT_API AMyCharacter : public ACharacter
{
    GENERATED_BODY()

public:
    // Sets default values for this character's properties
    AMyCharacter(const FObjectInitializer& ObjectInitializer);

protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;

public:    
    // Called every frame
    virtual void Tick(float DeltaTime) override;

    // Called to bind functionality to input
    virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

};

#include "MyCharacter.h"
#include "MyCharacterMovementComponent.h"

// Sets default values
AMyCharacter::AMyCharacter(const FObjectInitializer& ObjectInitializer)
  : Super(ObjectInitializer.SetDefaultSubobjectClass<UMyCharacterMovementComponent>(ACharacter::CharacterMovementComponentName))
{
     // Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;

}

// Called when the game starts or when spawned
void AMyCharacter::BeginPlay()
{
    Super::BeginPlay();

}

// Called every frame
void AMyCharacter::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

}

// Called to bind functionality to input
void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
    Super::SetupPlayerInputComponent(PlayerInputComponent);

}



CustomMovementComponent.h and .cpp




#pragma once

#include "CoreMinimal.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "MyCharacterMovementComponent.generated.h"

/**
 *
 */
UCLASS()
class MYPROJECT_API UMyCharacterMovementComponent : public UCharacterMovementComponent
{
    GENERATED_UCLASS_BODY()

};


#include "MyCharacterMovementComponent.h"

UMyCharacterMovementComponent::UMyCharacterMovementComponent(const FObjectInitializer& ObjectInitializer)
  : Super(ObjectInitializer)
{
}



I made a tutorial for documentation purposes in which this happens. It can be seen in How to use a custom Character Movement Component in a custom Character in UE4 - C++ - YouTube .