Customizing ECameraComponentFollow, ECameraComponentAim and ECameraExtensionBase
Last updated
Last updated
Customizing ECameraComponentFollow, ECameraComponentAim and ECameraExtensionBase is pretty simple. You can override these classes to create your own camera components guiding camera behaviours. The following steps take ECameraComponentFollow as an example.
Right click on Content Browser -> select "Blueprint Class"-> Search for "ECameraComponentFollow" -> click "Select".
Rename it as whatever you want. Here I name it MyFollowComponent. Open the blueprint class and you can see the "Functions" section on the left side of the blueprint window. There are several implementable functions in this section. You should implement the UpdateComponent function, while other functions, if meet your needs, can also be implemented.
In the UpdateComponent function, the first thing you should do is to check whether the follow target is valid or not. Right click on the blueprint and search for "Get Follow Target", you will get the reference to "Follow Target". Then connect it to the Is Valid node. Define a new Do Something node where you practically implement component behaviour and make a link from "Is Valid" to this node.
Write component logic in the new function. For example here I implement a simple top-down view camera. It gets the follow target's location and offsets it with a fixed vector. The result is the camera's location. Node Owning Actor is the camera actor that owns this component.
In the camera actor (of class ECameraBase
or sub-class of ECameraBase
), specify MyFollowComponent to the "Follow Component" property and set "Aim Component" to null. Go to the blueprint where you want to call this camera. Invoke the CallCamera node and specify "Camera Class", "Spawn Rotation" and "Follow Target". You can also specify blending parameters if you like.
Run the game and you will see camera now is above the character and tracks its position.