# Customizing Existing Components: ControlAim as An Example

Sometimes you want to slightly modify existing components rather than implementing a new component from scratch. ComponentCameraSystem offers an extensible solution for you to override existing components, but in a limited way.

Concretely, you can override an existing component, say *ScreenFollow*, to incrementally add functionality to it. But you cannot manipulate the implementation details of the component. You can only complement additional logic after the component has been executed. If you are familiar with programming, this is equivalent to first calling the **parent** method and then doing anything else.

Let us take *ControlAim* as an example. This component receives player input to control camera orientation. I want to implement an "auto-rotating" function, where camera will automatically rotate around the follow target if no input is received for a specific period of time.

1. Right click on Content Browser -> select "Blueprint Class" -> Search for "ControlAim" -> click "Select".
2. Rename it as whatever you want. Here I name it *MyControlAim*. 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. For this component, you should implement the **OnBecomeViewTarget** and **UpdateComponent** functions, while other functions, if meet your needs, can also be implemented.
3. Define some variables. `FollowTarget` is used to detect whether the follow target is moving. `WaitingTime` is the duration to wait for enabling auto-rotation. `RotateSpeed` is the self-rotation speed. `CachedFollowTargetLocation` is follow target's location at previous frame. `ElapsedWaitTime` is the elapsed time since no input is given. <br>

   <figure><img src="https://1253177398-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIc7aRtmwmEkkqEJZORmC%2Fuploads%2FZwb5S5YC07TnUa4o50on%2Fmyaim-variables.png?alt=media&#x26;token=14ba8cb7-1ce9-4807-aec7-f04dc318cbae" alt=""><figcaption></figcaption></figure>
4. In the **OnBecomeViewTarget** function, you should set `FollowTarget`. <br>

   <figure><img src="https://1253177398-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIc7aRtmwmEkkqEJZORmC%2Fuploads%2FfuJ4DyqFohxGFToy8wRe%2Fmyaim-viewtarget.png?alt=media&#x26;token=7fdd2048-d5d1-488e-ba0d-8395f7e961d6" alt=""><figcaption></figcaption></figure>
5. In the **UpdateComponent** function, first call the parent method, then call your custom **DoSomething** function. <br>

   <figure><img src="https://1253177398-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIc7aRtmwmEkkqEJZORmC%2Fuploads%2FB26SsDFQ00Z7npO8a14k%2Fmyaim-update.png?alt=media&#x26;token=6d4cdc26-71c2-46c6-8c4d-8584849f6361" alt=""><figcaption></figcaption></figure>
6. The **DoSomething** function is the place where you implement self-rotation. Below is a reference implementation but feel free to make your own. The workflow is simple: first check whether the follow target is moving or input rotation is received (via the *GetMouseDeltaX* and *GetMouseDeltaY* nodes). If true, reset `ElapsedWaitTime`, otherwise add increment to it. Next check if `ElapsedWaitTime` has exceeded `WaitingTime`, and if true, add rotation to camera. Last, update `CachedFollowTargetLocation`. It is particularly noteworthy when using `FollowTarget` I did not check its validity. But technically you should do this whenever you use it. <br>

   <figure><img src="https://1253177398-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIc7aRtmwmEkkqEJZORmC%2Fuploads%2FpjC08yJFfnIGz4sB9erF%2Fmyaim-do.png?alt=media&#x26;token=45c8ce1a-56b7-4a9a-a900-437720876c56" alt=""><figcaption></figcaption></figure>
7. In the camera actor (of class `ECameraBase` or sub-class of `ECameraBase`), specify *MyControlAim* to the "Aim Component" property and set "Follow Component" with *ScreenFollow*. Go to the blueprint where you want to call this camera. Invoke the *CallCamera* node and specify "Camera Class" and "Follow Target". You can also specify blending parameters if you like.
8. Run the game, wait for `WaitTime` seconds, and you will see camera is smoothly rotating around the follow target. When character moves or camera input is given, self-rotation will stop and you have to wait another `WaitTime` to enable it. <br>

   <figure><img src="https://1253177398-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIc7aRtmwmEkkqEJZORmC%2Fuploads%2FoydA5wvdiAFjXoNdnVe7%2Fself-rotate.gif?alt=media&#x26;token=2e8d479e-8d6a-4c50-9604-55342014c67b" alt=""><figcaption></figcaption></figure>
