Hey,
I have grid of hexagons, I want in Editor to snap movement of some actors to centers of hexes, What I am trying to do:
void AGameSceneUnit::PostEditMove(bool bFinished)
{
Super::PostEditMove(bFinished);
auto transform = GetActorTransform();
auto location = transform.GetLocation();
TArray<AActor*> FoundActors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AGameSceneHexMap::StaticClass(), FoundActors);
if(FoundActors.Num() == 0)
return;
AGameSceneHexMap* pSceneHexMap = Cast<AGameSceneHexMap>(FoundActors[0]);
if(pSceneHexMap == nullptr || pSceneHexMap->GetHexMap() == nullptr)
return;
int32 cube_x = -1, cube_y = -1, cube_z = -1;
pSceneHexMap->GetHexMap()->PosToHexCube(pSceneHexMap->HexSize, location[1], location[0], cube_x, cube_y, cube_z);
// cube to world pos
pSceneHexMap->GetHexMap()->HexCubeToPos(pSceneHexMap->HexSize, cube_x, cube_y, cube_z, location[1], location[0]);
// row column back to hex center
SetActorLocation(location);
}
But this code prevent actor movement in Editor at all, I think because location is not changed yet, any idas what I need to use?