Viewport Size doesn't work in C++ but works in Blueprints

So I’m trying to implement Edge Scrolling and I can’t seem to make it work using with none of these functions: APlayerController->GetViewportSize(…), GetWorld()->GameGameViewport()->GetViewportSize(…), UWidgetLayoutLibrary::GetViewportSize(…);
But when I tried to do the same thing in Blueprints and use ‘Get Viewport Size’ function, everything seems to work normally so how can I make it work in C++, what can I be missing?

P.S I’m using PlayerController->GetMousePosition() in both cases (BP and CPP)

Nevermind, apparently I had commented PlayerController->GetViewportSize and was using UWIdgetLayoutLibrary::GetMousePosition, which for some reason gives incorrect mouse position compared to the controller one

This should do the job:

FVector2D ViewportSize;
if (GEngine && GEngine->GameViewport) {
    GEngine->GameViewport->GetViewportSize(ViewportSize);
}

It probably would, my actual problem was with getting mouse position, not with viewport size :confused: :smiley:

Thank you for your response anyways!