This code in Blueprints works:
Though this code in C++ & Blueprints combined doesn’t:
void ATestActor::CallGetPlayerCameraManager()
{
APlayerCameraManager* CameraManager = GameplayStatics::GetPlayerCameraManager(GetWorld(), 0);
if (IsValid(GEngine))
GEngine->AddOnScreenDebugMessage(0, 3.f, FColor::Red, CameraManager->GetName());
}
In the second case where I use C++ the engine crashes due to access violation.
Debugging showed that the problem is that PlayerController is not yet created when I call it from C++, but I don’t understand why it works perfectly fine in Blueprints. For me it’s seems strange that calling the same exact function from C++ and Bluerpints causes different results. Any ideas?
P.S. It’s crucial to have that functionality in Construction Script because my Level Designers have to see the results in the viewport BEFORE playing.