Download

Unreal crashed after using GetWorldTimerManager().SetTimer() ... need help

Hi Experts,

I am trying to make a floating object that reach certain height then return to the starting location but when i add SetTimer function to delay a couple of sec before it return. The Unreal 4 is crashed and exit. Do you know why ? how can i find out what is the issues? Thanks



// Fill out your copyright notice in the Description page of Project Settings.

#include "FloatingPlatfrom.h"
#include "Components/StaticMeshComponent.h"
#include "TimerManager.h"

// Sets default values
AFloatingPlatfrom::AFloatingPlatfrom()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;

Mesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
RootComponent = Mesh;

StartPoint = FVector(0.f);
EndPoint = FVector(0.f);

// speed and time that platform stay on top
IntepSpeed = 4.0f;
IntepTime = 1.f;
}

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

StartPoint = GetActorLocation();
EndPoint += StartPoint; // end point is relative position to the platform and need to add platform begin location
Distance = (EndPoint - StartPoint).Size();
}

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

FVector Currentlocation = GetActorLocation();
FVector Interp = FMath::VInterpTo(Currentlocation, EndPoint, DeltaTime, IntepSpeed);
SetActorLocation(Interp);

float DistanceTravled = (GetActorLocation() - StartPoint).Size();

if (Distance - DistanceTravled < 1.f)
{
//Binding the function with specific variables
TimerDel.BindUFunction(this, FName("SwapVectors"), StartPoint, EndPoint);
GetWorldTimerManager().SetTimer(InterpTimer, TimerDel, 1.f,false);
}
}

void AFloatingPlatfrom::SwapVectors(FVector& VecOne, FVector& VecTwo)
{
FVector Temp = VecOne;
VecOne = VecTwo;
VecTwo = Temp;
}