Updating actors in the editor in Unreal Engine 4

Did you know that you can tick actors inside the editor viewport? It can be useful if you want to visualize how the moving actor will look and feel on the scene without even playing the game. And it is really easy to do! Unfortunatelly to do this you need to write some code. Simply override this one function inside the actor you want to tick:
// *.h
bool ShouldTickIfViewportsOnly() const override;

// *.cpp
bool ATickingActor::ShouldTickIfViewportsOnly() const
{
	return true;
}
And that's it! This actor will tick inside the editor viewport. The only thing left is to implement the actuall Tick function.
ATickingActor::ATickingActor()
{
    // Make this actor tickable
    PrimaryActorTick.bCanEverTick = true;
    
    // Add a static mesh to this actor
    Mesh = CreateDefaultSubobject<UStaticMeshComponent>("Mesh");
}

void ATickingActor::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);
    
    // Rotate mesh
    Mesh->AddWorldRotation(FRotator(0, 0, 48.f * DeltaTime));
}
Why would we like to do this? Maybe we have some fans in the scene that we want to rotate?


Have in mind that even when the Tick in code will run the Tick event in Blueprints won't!

Also make sure that Realtime Viewport Option is enabled!


But what if we would like to tick actor ONLY in the editor, but not during the game? To do this we simply have to override not Tick function, but TickActor function:
// *.h
void TickActor(float DeltaTime, enum ELevelTick TickType, FActorTickFunction& ThisTickFunction) override;

// *.cpp
void ATickingActor::TickActor(float DeltaTime, enum ELevelTick TickType, FActorTickFunction& ThisTickFunction)
{
    Super::TickActor(DeltaTime, TickType, ThisTickFunction);
    
    if (TickType == ELevelTick::LEVELTICK_ViewportsOnly)
    {
        // Do some ticking logic here
    }
}
What else can we do? We can update the Animation Blueprint in the Character Actor:
if (USkeletalMeshComponent * SKMesh = GetMesh())
{
    SKMesh->TickAnimation(DeltaTime, false);

    SKMesh->RefreshBoneTransforms();
    SKMesh->RefreshSlaveComponents();
    SKMesh->UpdateComponentToWorld();
    SKMesh->FinalizeBoneTransform();
    SKMesh->MarkRenderTransformDirty();
    SKMesh->MarkRenderDynamicDataDirty();
}
Or we can draw some debug shapes:
DrawDebugSphere(GetWorld(), GetActorLocation() + FVector(0, 0, GetCapsuleComponent()->GetScaledCapsuleHalfHeight() * 2.f), 24.f, 16, FColor::Green);

As you can see there are plenty of ways to use this feature from simply visualising stuff to making debuging easier. I hope this little thing will help you in your future projects. Cheers!