No announcement yet.

Crash caused by playing a timeline

  • Filter
  • Time
  • Show
Clear All
new posts

    Crash caused by playing a timeline

    I want my camera spring arm to lerp between different positions depending on whether my player is walking, running, crouching etc. Using a timeline makes sense for the lerp. Running it, however, instantly causes the editor to crash. This is using version 4.23.1.

    The relevant code, .h file:

    // Other includes irrelevant to question
    #include "Runtime/Engine/Classes/Components/TimelineComponent.h"
    #include "ALSCharacter.generated.h"
    class CPPCHARACTERMOVEMENT_API AALSCharacter : public ACharacter
        // Timeline component for lerping camera
        class UTimelineComponent* CameraTimeline;
        // Lerp curves required to update the camera. These need to be defined in the BP class which inherits from this class.
        UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Camera Lerp Curves")
        class UCurveFloat* uCurveCameraAiming;
        UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Camera Lerp Curves")
        class UCurveFloat* uCurveCameraNotAiming;
        // Camera and camera lerping utility functions
        void UpdateCamera(UCurveFloat* lerpCurve, float curveLength); // Updates the camera based on a Lerp curve
        FCameraSettings ChooseCameraSettings();          // Returns camera settings based on movement mode, bIsAiming, stance and gait
        void LerpBetweenCameraSettings(float lerpAlpha); // Lerps between the current camera settings and the desired camera settings
        FOnTimelineFloat InterpFunction;                 // Delegate for timeline's float track
        UFUNCTION()                        // The function which the timeline update is bound to. Effectively acts as a wrapper for
        void TimelineUpdate(float value);  // LerpBetweenCameraSettings(float lerpAlpha)
    The relevant code, .cpp file:

    //Other includes irrelevant to question
    #include "ALSCharacter.h"
    #include "Camera/CameraComponent.h"
    #include "Runtime/Engine/Classes/Components/TimelineComponent.h"
    #include "GameFramework/SpringArmComponent.h"
        // Create a spring arm
        SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
        SpringArm->TargetArmLength = 300.0f;
        SpringArm->bUsePawnControlRotation = true;
        // Create a camera
        ThirdPersonCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
        ThirdPersonCamera->SetupAttachment(SpringArm, USpringArmComponent::SocketName);
        ThirdPersonCamera->bUsePawnControlRotation = false;
        // Create timeline for camera lerp and bind the delegates to the appropriate functions
        CameraTimeline = CreateDefaultSubobject<UTimelineComponent>(TEXT("CameraTimeline"));
        InterpFunction.BindUFunction(this, FName("TimelineUpdate"));
    // Other things done in the constructor irrelevant to question
    // This function is called every time the player changes gait (e.g. goes from running to walking, or walking to crouching, etc.)
    void AALSCharacter::UpdateCamera(UCurveFloat* lerpCurve, float curveLength)
        if (lerpCurve)
            CameraTimeline->AddInterpFloat(lerpCurve, InterpFunction, FName("LerpAlpha"), FName("LerpAlpha"));
            CameraTimeline->SetFloatCurve(lerpCurve, FName("LerpAlpha"));
            CameraTimeline->PlayFromStart(); // <-- This is the line causing the crash. I know this, because if I comment out and recompile, no crash but also the timeline doesn't run.
    void AALSCharacter::TimelineUpdate(float value)
        //LerpBetweenCameraSettings(value); // Function which does the lerping math
        UE_LOG(LogTemp, Log, TEXT("Timeline playing..."));
    As soon as my character changes gait (e.g. I press left alt to change from running to walking), the editor freezes, crashes, and I get the following window:

    Click image for larger version  Name:	Fail.png Views:	0 Size:	89.3 KB ID:	1686857

    So why is this happening? It's not to do with the fact the lerp curve is invalid, because that is checked for. This is done almost exactly as it is done on the wiki. Maybe I've just missed something obvious... maybe this is a bug. Are there certain things which you cannot do in the constructors, which is why?
    Last edited by VD_D; 11-14-2019, 02:15 AM.

    After spending a bit of hair over this... It was the missing
    above the timeline component. Remember to set your uproperties....