Download

how to know when MoveComponentTo is done?

I’m using MoveComponentTo function to open and close a door but i don’t want to allow the users to close it or open it before the other function is done how do I that?

Code:
void ADoors::RecieveInteraction()
{
FLatentActionInfo Latentinfo;
Latentinfo.CallbackTarget = this;
FTimerHandle UnusedHandle;

if (bFlipFlop == false)
{
UKismetSystemLibrary::MoveComponentTo(DoorMesh, FVector((33.f, -3.f, 0.f)), FRotator(0.f, 90.f, 0.f), true, true, 0.8, true, EMoveComponentAction::Type::Move, Latentinfo);
bFlipFlop = true;
GetWorldTimerManager().ClearTimer(UnusedHandle);
}
else
{

UKismetSystemLibrary::MoveComponentTo(DoorMesh, FVector((33.f, -3.f, 0.f)), FRotator(0.f, 0.f, 0.f), true, true, 0.8, true, EMoveComponentAction::Type::Move, Latentinfo);

GetWorldTimerManager().SetTimer(UnusedHandle, this, &ADoors::PlayCloseSound, 0.8, false, 0.5);

bFlipFlop = false;
}

}

Example:

In .h file:



**UFUNCTION(BlueprintCallable)
void ****OnMoveComponentToEnd****();**


In .cpp file:



...
     FLatentActionInfo Latentinfo;
     Latentinfo.CallbackTarget = this;
     **Latentinfo.ExecutionFunction = "****OnMoveComponentToEnd";**
     **Latentinfo.Linkage = 0;**

     UKismetSystemLibrary::MoveComponentTo(Mesh, FVector((500.0f, 500.0f,0)), FRotator(0.f, 0,0), true, true, 2.0f, true, EMoveComponentAction::Type::Move, Latentinfo);

...


**void ASomeActor::OnMoveComponentToEnd()
{
    UE_LOG(LogTemp, Warning, TEXT("MoveComponentTo END"));
}**



this is what i did and it didn’t work? also where is that string coming from should I put the function name in it?

in h. file

Code:
UFUNCTION(BlueprintCallable)
void PlayClosingSound();

in cpp file

Code:

FLatentActionInfo LatentEnd;
LatentEnd.CallbackTarget = this;
LatentEnd.ExecutionFunction = “OnEnd”;
LatentEnd.Linkage = 0;
UKismetSystemLibrary::MoveComponentTo(DoorMesh, FVector((33.f, -3.f, 0.f)), FRotator(0.f, 0.f, 0.f), true, true, 0.8, true, EMoveComponentAction::Type::Move, Latentinfo);



LatentEnd.ExecutionFunction = "PlayClosingSound";


i clearly put the wrong FLatentActioninfo in there that’s why it wouldn’t work :stuck_out_tongue:

Yeah, I just edited the answer.