Hello, I am new and trying to Learn Unreal with C++.
I’ve run into an odd issue and I cannot seem to get a lot of material on how to solve this issue.
In short, I’ve created a Test_Class to learn how WordTimerManager.SetTimer works. Currently the class is testing the accuracy of the timer.
The issue that I am facing is that the Timer is not using the original instance of the class that has all of my initialized variables (or some other issue that I have not noticed). And this causes exceptions when trying to run this class.
I’ve setup the class as follows
UCLASS()
class RPG01_API ATest_Effect: public AActor{
GENERATED_BODY()
private:
/*
Some Variables
*/
tickrate;
FTimerHandle repeater;
FTimerDelegate delegate;
public:
ATest_Effect():
tickrate(0.1),
Var2...){
delegate.BindLambda([this](){tick(tickrate);});
PrimaryActorTick.bCanEverTick = false;
}
/*Other Function declarations*/
And the implementation as follows:
void ATest_Effect::BeginPlay()
{
Super::BeginPlay();
GetWorld()->GetTimerManager().SetTimer(repeater, delegate, tickrate, true);
Debug::Log(TEXT("Start Effect Test"));
}
bool ATest_Effect::Tick(float X){
// Sequence of tests
}
When Debugging the code i can see that the variables are properly initialized in the BeginPlay(); function.
But when I run the code until the fist time the game ticks my Tick(x) function, then the variables and pointer to *this changes:
Note: This is the only class / actor in this test world.
How do i prevent this from happening?