Found the solution!
When AActor moves, what actually moves is its Root Component.
There is a delegate USceneComponent::TransformUpdated
and Actor always has the Scene Component at its root so I can easily call GetOwner()->GetRootComponent()
and bind something to said delegate. I’m doing this inside of UActorComponent::OnComponentCreated
override.
Full code:
.h
/* Note: This is inside of class derived from UActorComponent */
virtual void OnComponentCreated() override;
.cpp
void UMyComponent::OnComponentCreated()
{
Super::OnComponentCreated();
const UWorld* const ThisWorld = GetWorld();
if (
this->HasAnyFlags(RF_Transient)
&& !IsValid(ThisWorld)
&& !ThisWorld->IsEditorWorld()
&& ThisWorld->IsPlayInEditor()
)
{
return;
}
auto OnOwnerTransformUpdated =
[this](USceneComponent* UpdatedComponent, EUpdateTransformFlags UpdateTransformFlag, ETeleportType Teleport)->void
{
/* Do stuff with transform here! */
};
GetOwner()->GetRootComponent()->TransformUpdated.AddLambda(OnOwnerTransformUpdated);
}
Result: