I created template from Top Down C++.
I commented out those lines as I don’t want to have attached camera to character:
// Create a camera boom…
/*
CameraBoom = ObjectInitializer.CreateDefaultSubobject<USpringArmComponent>(this, TEXT(“CameraBoom”));
CameraBoom->AttachTo(RootComponent);
CameraBoom->bAbsoluteRotation = true; // Don’t want arm to rotate when character does
CameraBoom->TargetArmLength = 800.f;
CameraBoom->RelativeRotation = FRotator(-60.f, 0.f, 0.f);
CameraBoom->bDoCollisionTest = false; // Don’t want to pull camera in when it collides with level
// Create a camera…
TopDownCameraComponent = ObjectInitializer.CreateDefaultSubobject<UCameraComponent>(this, TEXT(“TopDownCamera”));
TopDownCameraComponent->AttachTo(CameraBoom, USpringArmComponent::SocketName);
TopDownCameraComponent->bUsePawnControlRotation = false; // Camera does not rotate relative to arm
*/
Then I created camera in editor and activated by selecting :
Auto Player Activation / Auto Activate for Player —> Player 0
In C++ I got a handle to camera by :
// There is only one CameraActor
for (TActorIterator<ACameraActor> It(GetWorld()); It; ++It)
{
_mainCamera = *It;
}
→ called in BeginPlay()
Then I want to change the position of camera on MouseWheel like :
FVector PrevLocation = _mainCamera->GetCameraComponent()->GetRelativeTransform().GetLocation();
_mainCamera->SetActorRelativeLocation(FVector(PrevLocation.X, PrevLocation.Y, PrevLocation.Z - 10));
The problem is that it doesn’t work at first time. When I press the Play button in editor first time it doesn’t work. When I press stop and then Play again then it works.
Do you know why ? please ?
Thanks for anwer