I tried to make asynchronous nodes.
But after making it and running it, there was a warning.
this is my code:
.h:
UCLASS()
class TIMEMANAGERPLUGINS_API UCustomAsync : public UBlueprintAsyncActionBase
{
GENERATED_BODY()
public:
virtual void Activate() override;
virtual TStatId GetStatId() const;
public:
UPROPERTY(BlueprintAssignable)
FCustomAsync OnTime;
UPROPERTY(BlueprintAssignable)
FCustomAsync OnFinish;
private:
float CurrentTime = 0;
float AllTimerTime = 0;
bool bForwardTimer = false;
int32 AsyncCounter = 0;
ETimer Timer = ETimer::Pause;
FTimerHandle TimerHandle;
const UObject* WorldContextObject;
public:
UFUNCTION(BlueprintCallable, meta = (BlueprintInternalUseOnly = "true", WorldContext = "WorldContextObject"),Category="TimeMangerPlugins| Timer")
static UCustomAsync* StartClock(UObject* WorldContextObject, bool bForward,float SecondsTime);
};
.cpp
void UCustomAsync::Activate()
{
}
TStatId UCustomAsync::GetStatId() const
{
return TStatId();
}
UCustomAsync* UCustomAsync::StartClock(UObject* WorldContextObject, bool bForward, float SecondsTime)
{
if (!WorldContextObject)
{
FFrame::KismetExecutionMessage(TEXT("Invalid WorldContextObject. Cannot execute Set Timer."), ELogVerbosity::Error);
return nullptr;
}
if (SecondsTime<=0)
{
FFrame::KismetExecutionMessage(TEXT("Invalid WorldContextObject. SecondsTime <=0 is error!!!"), ELogVerbosity::Error);
return nullptr;
}
UCustomAsync* Node = NewObject<UCustomAsync>();
Node->WorldContextObject = WorldContextObject;
Node->AllTimerTime = SecondsTime;
Node->bForwardTimer = bForward;
auto TimeCheck = [Node, WorldContextObject]()
{
Node->CurrentTime += 0.1;
if (Node->CurrentTime >= Node->AllTimerTime)
{
Node->OnFinish.Broadcast(Node->CurrentTime);
Node->WorldContextObject->GetWorld()->GetTimerManager().ClearTimer(Node->TimerHandle);
}
if (Node->bForwardTimer)
{
Node->OnTime.Broadcast(Node->CurrentTime);
}
else
{
Node->OnTime.Broadcast((Node->AllTimerTime) - (Node->CurrentTime));
}
};
Node->WorldContextObject->GetWorld()->GetTimerManager().SetTimer(Node->TimerHandle, FTimerDelegate::CreateLambda(TimeCheck), 0.1f, true);
return Node;
}
I am not find problem,But when I tried to run the blueprint:
I do not know why.