Second CurveFloat is deleted at BeginPlay

Hello guys,

I’m passing a blueprint behaviour to C++ and in this case i need to handle two different CurveFloat variables like this:

For the first curve.

For the second one.

So, this this i created the next code:

UCLASS()
class SIDERUNNER_API ASideRunnerPaperCharacter : public APaperCharacter
{
	GENERATED_BODY()

	FTimeline OnDeathRotation;
	FTimeline OnPlayRotation;

	FTimerHandle ShowGameOverScreenDelayHandler;
	FTimerHandle StopMovementDelayHandler;

	UPROPERTY()
	class UCurveFloat *DeathRotation = nullptr;

	UPROPERTY()
	class UCurveFloat *PlayRotation = nullptr;

	bool bDoubleJump;

	class ASideRunnerGameModeBase *Ref_GameMode = nullptr;

	class UTextRenderComponent *TextComponent = nullptr;

	void BeginPlay() override;
	virtual void Tick(float DeltaSeconds) override;

protected:

For the header file: two CurveFloat pointers and two FTimeLine for use them.

 /* This is the way using a Blueprint Curve */
    static ConstructorHelpers::FObjectFinder<UCurveFloat> PlayCurve(TEXT("/Game/Blueprints/Utils/Curve_PlayRotation_Float"));
    check(PlayCurve.Succeeded());
    PlayRotation = PlayCurve.Object;

    static ConstructorHelpers::FObjectFinder<UCurveFloat> DeathCurve(TEXT("/Game/Blueprints/Utils/Curve_DeathRotation_Float"));
    check(DeathCurve.Succeeded());
    DeathRotation = DeathCurve.Object;

    /* This is the way creating the curve with code, it does not work for me 
    PlayRotation = NewObject<UCurveFloat>();
	PlayRotation->FloatCurve.AddKey(0.0f, 0.0f);
	PlayRotation->FloatCurve.AddKey(1.0f, -360.0f);

    DeathRotation = NewObject<UCurveFloat>();
    DeathRotation->FloatCurve.AddKey(0.f, 0.f);
    DeathRotation->FloatCurve.AddKey(1.f, -512.f);
    */

    FOnTimelineFloat TimelineCallback;
    FOnTimelineEventStatic TimelineFinishedCallback;

    TimelineCallback.BindUFunction(this, "RotatePlayer");

    if (PlayRotation)
    {
        OnPlayRotation.AddInterpFloat(PlayRotation, TimelineCallback, TEXT("Player Rotation"));
        OnPlayRotation.SetLooping(true);
        OnPlayRotation.SetTimelineLength(1.f);
        OnPlayRotation.SetTimelineLengthMode(ETimelineLengthMode::TL_TimelineLength);
    }
    else
    {
        UE_LOG(LogTemp, Warning, TEXT("There is no Curvefloat Object here!"));
    }

	if (DeathRotation)
	{
		OnDeathRotation.AddInterpFloat(DeathRotation, TimelineCallback, TEXT("Death Rotation"));
		OnDeathRotation.SetLooping(true);
		OnDeathRotation.SetTimelineLength(1.f);
		OnDeathRotation.SetTimelineLengthMode(ETimelineLengthMode::TL_TimelineLength);
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("There is no DeathRotation curve here!"));
	}

This code for the constructor.

void ASideRunnerPaperCharacter::RotatePlayer()
{
	float TimelineValue;
	float RotationFloatValue;

	/* As whatever the status of the character (dead ot not) the rotation will be the same workflow,
		and as we just change the Curve values, we handle both rotation behaviour in the same function
		based on the character's status
	*/
	if (bDeath)
	{
		TimelineValue = OnDeathRotation.GetPlaybackPosition();
		if (DeathRotation)
		{
			RotationFloatValue = DeathRotation->GetFloatValue(TimelineValue);
		}
		else
		{
			UE_LOG(LogTemp, Warning, TEXT("There is no such DeathRotation curve."));
		}
	} else
	{
		TimelineValue = OnPlayRotation.GetPlaybackPosition();

		if (PlayRotation)
		{
			RotationFloatValue = PlayRotation->GetFloatValue(TimelineValue);
		}
		else
		{
			UE_LOG(LogTemp, Warning, TEXT("There is no such PlayRotation curve."));
		}
	}

	GetSprite()->SetRelativeRotation(FRotator(RotationFloatValue, 0.f, 0.f));
}

This is the function which rotates the sprite based on the timeline value.

void ASideRunnerPaperCharacter::Tick(float DeltaSeconds)
{
    Super::Tick(DeltaSeconds);

    if (OnPlayRotation.IsPlaying())
        OnPlayRotation.TickTimeline(DeltaSeconds);

	if (OnDeathRotation.IsPlaying()) 
		OnDeathRotation.TickTimeline(DeltaSeconds);
}

Tick function for link the characters tick with the timeline time.

void ASideRunnerPaperCharacter::BeginPlay()
{
	// TODO: DeathRotation is being destriyed here
    Super::BeginPlay();

    UWorld *world = GetWorld();

    if (world)
    {
        Ref_GameMode = world->GetAuthGameMode<ASideRunnerGameModeBase>();
    }

    OnPlayRotation.Play();
}

The begin play function when the OnPlayRotation timeline is launched.

void ASideRunnerPaperCharacter::OnDeath()
{
    if (!bDeath)
    {
        bDeath = true;
        SetActorEnableCollision(false);
        LaunchCharacter(FVector(0.f, 0.f, JumpVelocity * 2), true, true);

        // TODO: Here make another timeline for OnDeathRotation
		OnPlayRotation.Stop();
		OnDeathRotation.Play();

        // This does not work: GetWorld()->GetTimerManager().SetTimer(DelayHandler, 0.2f, false);
        GetWorld()->GetTimerManager().SetTimer(ShowGameOverScreenDelayHandler, this, &ASideRunnerPaperCharacter::ShowGameOverScreen, 2.5f);

        GetWorld()->GetTimerManager().SetTimer(StopMovementDelayHandler, this, &ASideRunnerPaperCharacter::StopMovement, 4.f);
    }
}

And finally, the function when the second timeline must to be launched.

At launche the editor both CurveFloat are created correctly:

But after the begin play it is nullified:

After finishing the game and relaunch it:

And after begin play i have the same error again, i tried to sovle it playing the second timeline in the BeginPlay function but it also didn’t work.

So, what’s is my mistake here?
Thank you very much for your help.