keywords: [UE4]Camera related

keywords: CameraComponent, PlayerController, PlayerCameraManager

Set default PlayerCameraManager

Set PlayerCameraManagerClass in constructor of PlayerController:

PlayerCameraManagerClass = AMyPlayerCameraManager::StaticClass();
How to Get PlayerCameraManager
APlayerCameraManager* UGameplayStatics::GetPlayerCameraManager(const UObject* WorldContextObject, int32 PlayerIndex)
Enable camera rorate by controller, not keep the same rotation of character

CPP

USpringArmComponent::bAbsoluteRotation = true;

Blueprint

Limit rotate range of camera

When execute APlayerController->AddPitchInput(), Camera would look up in limited range by default: from -90 degrees down to 90 degrees up.
This limited range is affected by properties of PlayerCameraManager, there’re 6 properties to limit the range of camera rotation:

/** Minimum view pitch, in degrees. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=PlayerCameraManager)
float ViewPitchMin;

/** Maximum view pitch, in degrees. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=PlayerCameraManager)
float ViewPitchMax;

/** Minimum view yaw, in degrees. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=PlayerCameraManager)
float ViewYawMin;

/** Maximum view yaw, in degrees. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=PlayerCameraManager)
float ViewYawMax;

/** Minimum view roll, in degrees. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=PlayerCameraManager)
float ViewRollMin;

/** Maximum view roll, in degrees. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=PlayerCameraManager)
float ViewRollMax;
Custom CameraComponent and Default Camera in PlayerCameraManager

There does not have to be a CameraComponent anywhere by default.
The PlayerController creates a PlayerCameraManager which is all that is needed.
However, most projects want control over camera parameters and that is done via a CameraComponent.
The PlayerCameraManager’s default parameters are overridden by a CameraComponent via the documented responsibility chain. In the samples, e.g. “Top Down”, the CameraComponent can be found inside the character’s Blueprint under the Components tab, possibly nested under a SpringArmComponent.

Get Camera Location and Rotation

PlayerCameraManager.h

/**
 * Master function to retrieve Camera's actual view point.
 * Consider calling PlayerController::GetPlayerViewPoint() instead.
 *
 * @param    OutCamLoc    Returned camera location
 * @param    OutCamRot    Returned camera rotation
 */
void GetCameraViewPoint(FVector& OutCamLoc, FRotator& OutCamRot) const;

/** @return Returns camera's current rotation. */
UFUNCTION(BlueprintCallable, Category = "Camera")
FRotator GetCameraRotation() const;

/** @return Returns camera's current location. */
UFUNCTION(BlueprintCallable, Category = "Camera")
FVector GetCameraLocation() const;
How to set offset of SpringArm and CameraComponent

Set SocketOffset or TargetOffset, SocketOffset is at end of spring arm, TargetOffset is at start of spring.

/** offset at end of spring arm; use this instead of the relative offset of the attached component to ensure the line trace works as desired */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Camera)
FVector SocketOffset;

/** Offset at start of spring, applied in world space. Use this if you want a world-space offset from the parent component instead of the usual relative-space offset. */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Camera)
FVector TargetOffset; 

If want to relative location of CameraComponent, don’t use SetRelativeLocation or AddRelativeLocation on SpringArmComponent, otherwise there is jolt on camera where character moving.

How to disable collision detect of SpringArm

Set bDoCollisionTest to false,

USpringArmComponent::bDoCollisionTest = false;
How to disable WASD for camera movement

Set bAddDefaultMovementBindings to false in the customzied DefaultPawn Constructor, default value is true.

example:

AMySpectatorPawn::AMySpectatorPawn(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
    bAddDefaultMovementBindings = false;
}

AMyCameraGameMode::AMyCameraGameMode(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
    SpectatorClass = AMySpectatorPawn::StaticClass();
    DefaultPawnClass = AMySpectatorPawn::StaticClass();
}

Reference
https://answers.unrealengine.com/questions/193289/is-there-a-way-to-disable-wasd-for-camera-movement.html

How to full-screen display for camera view

Uncheck Constrain Aspect Ratio on CameraComponent.

How to switch camera in sequencer seamlessly

There’s no way to blend view seamlessly in two cameras, if you want to play in One Shot, you must use only one camera.

Blend from normal camera to Look at tracking camera in sequencer?
https://forums.unrealengine.com/development-discussion/animation/1679522-blend-from-normal-camera-to-look-at-tracking-camera-in-sequencer

Cinamatic Camera

How to set Focal Length by tracing

Reference

Where is the default camera component?
https://answers.unrealengine.com/questions/26286/where-is-the-default-camera-component.html

Player-Controlled Cameras
https://docs.unrealengine.com/en-US/Programming/Tutorials/PlayerCamera

Game-Controlled Cameras
https://docs.unrealengine.com/en-US/Programming/Tutorials/AutoCamera


养老江湖外,藏名诗画中。----白狼