How do i change the camera FOV using C++?

Check if you set you PlayerCameraManager class property in your PlayerController class or else it gonna use default one

If you did that and still don’ work try doing Super::UpdateCamera(DeltaTime); before your code as parent code may overwrite your code doings (in general you should do Super before if you want to overwrite what parent class does :p) or some other function doing that. go study source code of that class:

https://github.com/EpicGames/UnrealEngine/blob/4.2/Engine/Source/Runtime/Engine/Private/PlayerCameraManager.cpp

Also you don’t need to override PlayerCameraManager to change FOV, you can simply send call to camera manager and you can do it in character or playercontroller tick:

PlayerCameraManager->SetFOV(45);

I’m trying to implement the fov animation when going into Aim Down Sight. I looked into the Shooter Game example and i created a MyPlayerCameraManager and a MyPlayerController setting the MyPlayerCameraManager as the class. I overriden the UpdateCamera method and used the following code:

void AMyPlayerCameraManager::UpdateCamera(float DeltaTime)
{
	class AMyCharacter * Character = PCOwner ? Cast<AMyCharacter>(PCOwner->GetPawn()) : NULL;

	if (Character != NULL)
	{
		bool IsAiming = Character->IsAiming();

		const float TargetFOV = IsAiming ? 60.0f : 90.0f;

		DefaultFOV = FMath::FInterpTo(DefaultFOV, TargetFOV, DeltaTime, 20.0f);
	}

	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, FString::Printf(TEXT("%f"), DefaultFOV));

	Super::UpdateCamera(DeltaTime);
}

The values that are printed on the screen are fine, so the interpolation is working, but the FOV doesn’t change at all, so i guess this isn’t the variable i should be editing, but this is what they use on the Shooter Game, so what am i doing wrong?

Thnks for the response. Yes it’s running my custom PlayerCameraManager, it just doesn’t change anything. I’ve tried calling super first, but it’s the same result. Yes i knew about SetFOV and it works but I was trying to use the same way as the Shooter Game, because it works fine, so i was just curious in finding out what i’m missing.

Study source code, mayb you need to override something :slight_smile: or look on Shooter demo code

I searched and didn’t find it, that’s why i’m asking here :stuck_out_tongue:

You need to apply your PlayerController in GameMode constructor under GameMode.cpp.

Ex:
ADemoGameMode::ADemoGameMode(const FObjectInitializer& ObjectInitializer:Super(ObjectInitializer)
{
PlayerControllerClass = ADemoPlayerController::StaticClass();
}

This happened to me too, ¿Are you using a Camera Component on your character? Because if you take a look at the ShooterCharacter code, there is no camera, so there is no need for the SetFOV() on the CameraManager. I ran some tests, just to confirm, and DefaultFOV works without a camera attached to my main character, while SetFOV worked when I the camera component is added to my character.

I hope you find this useful.