First, here’s code :
//Constructor
AFPSurvivalCharacter::AFPSurvivalCharacter()
{
// Set size for collision capsule
GetCapsuleComponent()->InitCapsuleSize(55.f, 96.0f);
// set our turn rates for input
TurnRateGamepad = 45.f;
// Create a CameraComponent
FirstPersonCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("FirstPersonCamera"));
FirstPersonCameraComponent->SetupAttachment(GetCapsuleComponent());
FirstPersonCameraComponent->SetRelativeLocation(FVector(-39.56f, 1.75f, 64.f)); // Position the camera
FirstPersonCameraComponent->bUsePawnControlRotation = true;
// Create a mesh component that will be used when being viewed from a '1st person' view (when controlling this pawn)
Mesh1P = CreateDefaultSubobject<USkeletalMeshComponent>(TEXT("CharacterMesh1P"));
Mesh1P->SetOnlyOwnerSee(true);
Mesh1P->SetupAttachment(FirstPersonCameraComponent);
Mesh1P->bCastDynamicShadow = false;
Mesh1P->CastShadow = false;
Mesh1P->SetRelativeRotation(FRotator(1.9f, -19.19f, 5.2f));
Mesh1P->SetRelativeLocation(FVector(-0.5f, -4.4f, -155.7f));
SprintMultiplier = 1.7f;
CrouchMultiplier = 0.6f;
SpeedMap.Reserve(3);
SpeedMap.Add(EMovementState::Walking, GetCharacterMovement()->MaxWalkSpeed);
SpeedMap.Add(EMovementState::Sprinting, GetCharacterMovement()->MaxWalkSpeed * SprintMultiplier);
SpeedMap.Add(EMovementState::Crouching, GetCharacterMovement()->MaxWalkSpeed * CrouchMultiplier);
SpeedMap.Add(EMovementState::Sliding, NULL);
ButtonPressed.Reserve(2);
ButtonPressed.Add("Sprint", false);
ButtonPressed.Add("Crouch", false);
CurrentJumpCount = 0;
MaxJumpCount = 2;
MovementState = EMovementState::Walking;
PrevMovementState = EMovementState::Walking;
SlideTimeline = CreateDefaultSubobject<UTimelineComponent>(TEXT("SlideTimeline"));
SmoothCrouchingTimeline = CreateDefaultSubobject<UTimelineComponent>(TEXT("CrouchingTimeline"));
CameraTiltTimeline = CreateDefaultSubobject<UTimelineComponent>(TEXT("TiltTimeline"));
StandingCapsuleHalfHeight = GetCapsuleComponent()->GetScaledCapsuleHalfHeight();
StandingCameraZOffset = GetFirstPersonCameraComponent()->GetRelativeLocation().Z;
DefaultGroundFriction = GetCharacterMovement()->GroundFriction;
DefaultBrakingDeceleration = GetCharacterMovement()->BrakingDecelerationWalking;
}
void AFPSurvivalCharacter::BeginPlay()
{
// Call the base class
Super::BeginPlay();
SlideTimelineFunction.BindUFunction(this, FName("SlideTimelineReturn"));
SlideTimeline->AddEvent(0, SlideTimelineFunction);
SlideTimeline->SetTimelineLength(1.0);
SlideTimeline->SetLooping(true);
CameraTiltTimelineFunction.BindUFunction(this, FName("CameraTiltReturn"));
if(CameraTiltCurveFloat)
{
CameraTiltTimeline->AddInterpFloat(CameraTiltCurveFloat, CameraTiltTimelineFunction);
CameraTiltTimeline->SetTimelineLength(0.3);
CameraTiltTimeline->SetLooping(false);
}
SmoothCrouchTimelineFunction.BindUFunction(this, FName("SmoothCrouchTimelineReturn"));
if(SmoothCrouchingCurveFloat)
{
//Error! WHY??????
SmoothCrouchingTimeline->AddInterpFloat(SmoothCrouchingCurveFloat, SmoothCrouchTimelineFunction);
SmoothCrouchingTimeline->SetTimelineLength(0.3);
SmoothCrouchingTimeline->SetLooping(false);
}
}
void AFPSurvivalCharacter::SmoothCrouchTimelineReturn(float Value)
{
const auto CrouchedHeight = GetCharacterMovement()->GetCrouchedHalfHeight();
GetCapsuleComponent()->SetCapsuleHalfHeight(FMath::Lerp(CrouchedHeight, StandingCapsuleHalfHeight, Value));
const auto RelativeLocation = FirstPersonCameraComponent->GetRelativeLocation();
FirstPersonCameraComponent->SetRelativeLocation(FVector(RelativeLocation.X, RelativeLocation.Y, (FMath::Lerp(CrouchedHeight, StandingCameraZOffset, Value))));
}
void AFPSurvivalCharacter::SlideTimelineReturn()
{
const auto SlideDirection = CalculateFloorInfluence(GetCharacterMovement()->CurrentFloor.HitResult.Normal);
GetCharacterMovement()->AddForce(SlideDirection);
if(GetVelocity().Length() > SpeedMap[EMovementState::Sprinting])
{
auto velocity = GetVelocity();
velocity.Normalize();
GetCharacterMovement()->Velocity = velocity * SpeedMap[EMovementState::Sprinting];
}
if(GetVelocity().Length() < SpeedMap[EMovementState::Crouching])
{
ResolveMovementState();
}
}
and here’s Crash Log…
Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0x00000000000000f0
UnrealEditor_Engine!FTimeline::AddInterpFloat() [D:uild++UE5SyncEngineSourceRuntimeEnginePrivateTimeline.cpp:114]
UnrealEditor_Engine!UTimelineComponent::AddInterpFloat() [D:uild++UE5SyncEngineSourceRuntimeEnginePrivateTimeline.cpp:777]
UnrealEditor_FPSurvival_4743!AFPSurvivalCharacter::BeginPlay() [C:UserskcjseDesktopProject-FPSurvivalSourceFPSurvivalFPSurvivalCharacter.cpp:93]
UnrealEditor_Engine!AActor::DispatchBeginPlay() [D:uild++UE5SyncEngineSourceRuntimeEnginePrivateActor.cpp:3849]
and Github Repo - (Project-FPSurvival/FPSurvivalCharacter.cpp at main · kcjsend2/Project-FPSurvival · GitHub)
When I access member function of SmoothCrouchingTimeline, UE5 crashes.
Project is based on FPS Template.
I try to figure this out for three days, but I CANT FIND ANYTHING WRONG…
Spelling, GC, UPROPERTY, UFUNCTION… Everything looks fine, but it doesn’t work.
this makes me pain a lot… please help.