Please Help : How do i switch the main/target camera in c++

This is the 4th time ive posted this question and i havent gotten any good answers, So i have two camera components in my player (FirstPersonCameraComponent) and (ThirdPersonCameraComponent) i already know how to trigger somthing on key press in c++ but i want to know how to set the main camera on key press like done in this blue print

4300-camsetup.jpg

is it possible to do something like this in c++ (i made a rough none working line of code)

if not, can someone go more in depth on what i should do to set the main camera on key press in c++ because so far its been error after error and its became frustrating. thanks to anyone how takes the time to answer and can you respond to my reply to you answer. thanks

2 Likes

Yes, you can just get the controller of player and SetViewTarget or SetViewTargetWithBlend with new camera could work. So it will be smth like this:

FViewTargetTransitionParams Params;
GetController()->SetViewTarget(NewCamera, Params);
1 Like

Oh I fotgot it’s in Player controller

APlayerController* Controller = Cast<APlayerController>(Getcontroller());
1 Like

it says error AController has no member of setviewtarget

nope :confused: still getting that error

12704-code.png

Except it isnt working for my camera component

it’s Controller->SetViewTarget

Oh wait you want to switch camera on same actor right ? if that do this instead

//Activate 3rd person
FirstPersonCameraComponent->Deactivate();
ThirdPersonCameraComponent->Activate();

//Activate 1st person
ThirdPersonCameraComponent->Deactivate();
FirstPersonCameraComponent->Activate();
1 Like

ive just added this to my on input and now it crashes when i press the input key