Download

[Help] GetActorLocation always returning 0,0,0

I am trying to make a simple match three game.

As part of this I want to get the location of the cell that is clicked on to swap gems as needed.

“GetActorLocation” when called in the blueprint seems to get the correct value

However when I try to get the location of the cell in C++ I always get the same result.

C++ code:



void AMatchThreePlayerController::handleMouseSelect(bool hitOccured, ACell* hitCell) {

    //if (hitOccured && hitCell != nullptr) {
    if (hitOccured && IsValid(hitCell)) {

        if (IsValid(currentSelectedCell)) {
            if (currentSelectedCell == hitCell) {
                currentSelectedCell->endMouseSelect();
                currentSelectedCell = nullptr;
            }
            else if (currentSelectedCell->isNeighbourOf(hitCell)) {
                if (IsValid(gameGrid)) {
                    UE_LOG(LogTemp, Warning, TEXT("currentSelectedCell loc    %d, %d, %d"), currentSelectedCell->GetActorLocation().X, currentSelectedCell->GetActorLocation().Y, currentSelectedCell->GetActorLocation().Z);
                    UE_LOG(LogTemp, Warning, TEXT("hitCell loc                %d, %d, %d"), hitCell->GetActorLocation().X, hitCell->GetActorLocation().Y, hitCell->GetActorLocation().Z);
                    //gameGrid->doGemSwap(currentSelectedCell, hitCell);
                }
                currentSelectedCell->endMouseSelect();
                currentSelectedCell = nullptr;
            }
            else {
                currentSelectedCell->endMouseSelect();
                hitCell->startMouseSelect();
                currentSelectedCell = hitCell;
            }
        }
        else {
            hitCell->startMouseSelect();
            currentSelectedCell = hitCell;
        }
    }
    else if (IsValid(currentSelectedCell)) {
        currentSelectedCell->endMouseSelect();
        currentSelectedCell = nullptr;
    }
}


Output:

Any suggestions on how to resolve this issue?

If you want to log an FVector (floating point precision) you can either use


*GetActorLocation().toString()

or you can log each component using %f.