Get offset in editor when moving actor in code

Hi!

When I run the following code:

void ATestUnit::PostEditMove(bool bFinished)
{	
	if (bFinished && RootComponent != nullptr)
	{
		auto loc = this->GetActorLocation();

		// Should only be allowed to be placed in tiles of a grid
		loc.Y = ((int)loc.Y) / tileSize * tileSize ; // couldn't find any fmod function...
		loc.X = ((int)loc.X) / tileSize * tileSize ;
		loc.Z = 0;

		RootComponent->SetWorldLocation(loc);
	}
	AActor::PostEditMove(bFinished);
}

I get an offset from the xyz arrows to the actor’s mesh representation. However if I just selects the actor again there is no longer any offset for the xyz arrows. It’s not very much of a problem but is this the expected behavior of this code. If so am I missing some update call to the editor or something? (The mesh is the root component node.)

That’s basically the same thing we’re doing internally to make our actors on fortnite snap to a grid. You may want to try this as well, I can’t remember if this updates the widget, but it does force some things to redraw:

FEditorSupportDelegates::RedrawAllViewports.Broadcast();

Also, FMath::GridSnap is a good way to do that, it’s a fmod + round

FMath::GridSnap can come handy. FEditorSupportDelegates::RedrawAllViewports.Broadcast(); doesn’t seems to fix the offset problem though.

I think I remember us trying to solve it, and then just living with the issue. It wasn’t a big deal in practice with our level designers

Okay, thank you for the help =) I will consider the question solved.