In this post we will explore how to use the universal camera plugin in Unreal Engine.
In particular, we will be integrating it with our Top Down / Third person character blueprint.
There’s several other posts handling camera in Unreal Engine without the use of the plugin, if you don’t want to purchase this plugin, perhaps check those out, they can achieve similar things but obviously a little more complicated as they are more manual.
- Rotate the object rather than camera and zoom
- Handle Rotate and zoom using SpringArm component on Camera
- Rotate and Zoom using camera properties
Getting started
Remember, the plugin page in Unreal Engine store has the documentation there so check that out for updates!
First, install the plugin to your engine.
After installing it, open your project and enable the plugin, by clicking Edit -> Plugins and finding the plugin to enable.
Creating the camera
In order to create the universal camera, right click and create new Blueprint Class.
Next, in the pop up window, search for the UniversalCamera.
You can see I created mine with the name of PlayerCameraBP – you can call yours whatever you like.
Next, all you need to do is add the camera component into the Spring Arm component that’s inside the created blueprint.
You don’t need to add anything else into the Blueprints here.
Updating Character BP to support universal camera
First of all, if your character blueprint includes a camera, you can delete it now, as we will be using the universal camera component.
Next, create a new graph to handle the camera logic, not to mix it with other logic.
Call it as you like, perhaps something like ‘CameraControlGraph‘.
Let’s now start adding some blueprints into this graph.
Create a Custom event, mine is called PrepareUniversalCamera – this will be used part of event begin play, we will cover this a little later.
First thing we want to do is Spawn the Player Camera BP – this is the Universal Camera blueprint component we created in one of the previous steps. We promote it to a local variable as we will need this reference in few other steps later.
Next, we set the view target with Blend, this is basically connecting the player controller with the camera component.
We then tell the Camera Component to follow the actor (self).
After telling the camera to follow the actor (this effectively replicates the camera being nested into the character), we want to configure some properties, to make zoom available and work as we like.
First, we want to add the Mapping Context. Before we do that, let’s discuss what it is and how to set it up.
Enhanced Input Actions
The Enhanced input actions are effectively replacing the default engine Inputs, so let’s look at using those.
The process is a little more complex, but there’s a lot more features that can be utilized with them.
First let’s create a basic Input Action. You can do so by right clicking -> Input -> Input Action.
I have created 3 input actions, one for moving the mouse (to capture the co-ordinates of the mouse move), another one to capture when the right mouse button is pressed and final one to capture zoom (mouse wheel up/down).
Let’s check out the Mouse Move action:
The main thing to see here is the Value Type which is Axis2D.
Then we have the Right Mouse Pressed action.
This is a simple Digital Value type.
And finally we have the Zoom Action, which is a Axis1D value type.
Now that we’ve defined the Actions, we want to collect them together and make available. We do this through the Input Mapping Context blueprint – so create that (right click -> input -> input mapping context).
In this input mapping context we can link the actions to the actual inputs being pressed and below you can find the definition.
As you can see, the zoom is connected to the mouse wheel axis. This therefore can provide us the 1D axis that we’ve setup in the action.
This completes the setup for the enhanced input and you’re now ready to go back to character blueprint to set this up.
Completing the character blueprint
With reference to this blueprint:
We’ve defined the Input Mapping Context that we can now connect to the player controller. This is exactly what the Add mapping context function is doing here, we select the created config that we link to the player controller.
This essentially registers the inputs that we can now use.
Before we dive into those implementation, we can just configure the minimum and maximum zoom – as well as enabling the constrain for the maximum zoom. Feel free to configure them as you require.
After registering the mapping context, you will have several new functions available in your blueprint, specifically the actions for zoom, right mouse press and mouse move. Let’s look at the first one, the Zoom action.
This is pretty straight forward now – the IA Zoom provides us with the 1D action value for our mouse wheel rotation. we can feed that straight into the Camera component: Zoom In function. Play around with the multiplier as you like to handle sensitivity.
Next, we can implement the right mouse action:
Here we simply promote it to variable, this is so we can ‘drag to rotate the camera’. This will be used with the mouse move action, that we can see below:
For the mouse move action, we want to Rotate the camera around pivot when the right mouse button is pressed and we move the mouse.
Therefore you can see me first check if the right mouse button is pressed, then if so, I Rotate yaw/pitch around pivot using the camera component. You can see that I receive the 2D vector from the action value of the mouse move event.
Finally, don’t forget to connect this to the Event Begin Play!
And that’s it, you’ve configured the camera for your character!