🚀 Spring Sale is live! 🚀 Don't miss your chance to get all my products at 30% OFF!  

Get it!

Camera System

Setting Up the Camera System Component

To add the GCMS_CameraSystemComponent to your character, ensure that your character has both a spring arm and a camera component attached.

通用相机系统.001

Initializing the Camera System Component

Next, call the following function to initialize the camera system component when beginplay:

通用相机系统.002

You will also need to specify a default camera mode class in the component's details panel.

通用相机系统.003

Switching Camera Modes

Switching camera modes is as simple as calling this one API:

通用相机系统.004

Creating Camera Mode

To create a new camera mode, simply create a blueprint that inherits from GCMS_CameraMode. It is recommended to prefix your camera modes with CM_.

通用相机系统.005

Default Parameters

A newly created camera mode comes with the following default parameters:

通用相机系统.006

The most notable part is the Blending section, where you can adjust the blending method and duration for the camera mode.

The View variable is a blueprint read/write structure. The main purpose of camera mode is to update this View structure while active and serve as the "output" for that camera mode.

Writing Camera Mode Logic

A camera mode provides several functions for you to override:

通用相机系统.007

Pivot Location and Rotation

The PivotLocation and PivotRotation functions already have default implementations with comments explaining their purpose. Generally, you do not need to override these two functions unless you want to customize the pivot points for the camera.

Lifecycle Functions

You can override OnActivation and OnDeactivation to perform initialization and cleanup tasks, similar to an Actor's BeginPlay and EndPlay.

通用相机系统.008

Updating the Camera Mode View

The core part of a camera mode is updating the camera mode View in the OnUpdateView function based on your actual game logic.

通用相机系统.009

You can access information beyond the camera mode through AssociatedCamera, AssociatedSprintArm, and TargetActor, allowing you to customize your logic based on this information. OnUpdateView will be executed every frame while the camera mode is active.

Reusable Camera Modes

GCMS not only provides a basic code structure for you to create different camera modes based on your project requirements, but it also includes several built-in camera modes with more default parameters that are ready to use.

For example, here is a camera mode suitable for third-person games:

通用相机系统.010

This mode offers additional default parameters, allowing you to drive the camera mode View's parameters using curve values or fixed values. You can create more camera modes by using it as a parent class and adjusting the curves, blending types, blending durations, and other parameters to achieve different camera control effects.

Use Case

通用相机系统.011

In this example, I have three different camera modes. The default mode is CM_ThirdPerson. If I am aiming, it switches to CM_ThirdPerson_ADS, and if I am targeting an enemy, it uses CM_ThirdPerson_Targeting.

Here’s how these camera modes appear in the actual game:

Extendability

The camera system component is not limited to character-based Actors; you can apply it to any Actor and add various camera modes. You can switch between these modes based on game logic. For instance, in a resource management game, you might control a camera actor and manage your camp in Topdown camera mode during certain scenarios.