# How to access camera component in Player Controller?

**URL:** <https://forums.unrealengine.com/t/how-to-access-camera-component-in-player-controller/641277>\
**Category:** C++\
**Tags:** UE4-20, unreal-engine, UE5-0, UE4, question, CPP\
**Created:** [September 4, 2022, 5:11pm UTC](https://forums.unrealengine.com/t/how-to-access-camera-component-in-player-controller/641277 "2022-09-04T17:11:50Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [September 4, 2022, 5:11pm UTC](https://forums.unrealengine.com/t/how-to-access-camera-component-in-player-controller/641277/1 "2022-09-04T17:11:50Z")

</div>

I want to access the camera in controller class, how to do it?

MyController.cpp

```auto
ACharacter* Character{};
AMyCharacter* MyCharacterRef{};
Character = UGameplayStatics::GetPlayerCharacter(this, 0);
MyCharacterRef = Cast<AMyCharacter>(Character);

```

```auto
FVector CamLocation = MyCharacterRef->Camera->UCameraComponent->GetComponentLocation();

```

I got an error pointer to incomplete type is not allowed. `MyCharacterRef`

---

<div class="post-metadata">

**Author:** ![jwatte](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jwatte/32/744941_2.png) [@jwatte](https://forums.unrealengine.com/u/jwatte)\
**Post date:** [September 4, 2022, 5:32pm UTC](https://forums.unrealengine.com/t/how-to-access-camera-component-in-player-controller/641277/2 "2022-09-04T17:32:38Z")

</div>

You need to include the header for your MyCharacter class in your MyController source file.

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [September 4, 2022, 6:31pm UTC](https://forums.unrealengine.com/t/how-to-access-camera-component-in-player-controller/641277/3 "2022-09-04T18:31:45Z")

</div>

already included, but still i am unable to access the character camera

---

<div class="post-metadata">

**Author:** ![jwatte](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jwatte/32/744941_2.png) [@jwatte](https://forums.unrealengine.com/u/jwatte)\
**Post date:** [September 4, 2022, 6:48pm UTC](https://forums.unrealengine.com/t/how-to-access-camera-component-in-player-controller/641277/4 "2022-09-04T18:48:57Z")

</div>

If you are correctly including the header, then you will not get that error.

How about you post a copy-and-paste of the actual error message text?  
And perhaps copy the `#include` parts of your `MyCharacter.cpp` file and paste it as a code block, too?

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [September 4, 2022, 7:01pm UTC](https://forums.unrealengine.com/t/how-to-access-camera-component-in-player-controller/641277/5 "2022-09-04T19:01:13Z")

</div>

Mycontroller.h  
`#include "AllCharacters/MyCharacter.h"`

Mycontroller.cpp  
`class AMyCharacter`

`Error (active)|E0393|pointer to incomplete class type is not allowed`

---

<div class="post-metadata">

**Author:** ![herb64](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@herb64](https://forums.unrealengine.com/u/herb64)\
**Post date:** [September 4, 2022, 8:07pm UTC](https://forums.unrealengine.com/t/how-to-access-camera-component-in-player-controller/641277/6 "2022-09-04T20:07:36Z")

</div>

Shoudn’t it be

Include in Mycontroller.cpp  
`#include "AllCharacters/MyCharacter.h"`

Forward declaration in Mycontroller.h  
`class AMyCharacter;`

---

<div class="post-metadata">

**Author:** ![jwatte](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jwatte/32/744941_2.png) [@jwatte](https://forums.unrealengine.com/u/jwatte)\
**Post date:** [September 4, 2022, 8:52pm UTC](https://forums.unrealengine.com/t/how-to-access-camera-component-in-player-controller/641277/7 "2022-09-04T20:52:23Z")

</div>

It’s not clear which class it’s complaining about.  
It may be complaining about the camera reference, or the camera component.  
You need to include the headers for all the classes your pointers will travel through.  
Thus, the type of the field “Camera” needs to be known (included) and the type of the field “UCameraComponent” of THAT type also needs to be known.  
(Which is kinda weird, btw – most of the type, fields aren’t named the same as the class of the value of the field.)

This is all plain C++ language questions; you may actually have better luck asking in a C++ specific forum. Nothing about these rules are specific to Unreal Engine. (Although, of course, the specifics about how Unreal lays out its headers are specific to Unreal, and if you ask in a language forum, they might in turn ask about that to be able to answer …)

---

<div class="post-metadata">

**Author:** ![Alexa.Ki](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alexa.ki/32/562753_2.png) [@Alexa.Ki](https://forums.unrealengine.com/u/Alexa.Ki)\
**Post date:** [September 5, 2022, 8:37am UTC](https://forums.unrealengine.com/t/how-to-access-camera-component-in-player-controller/641277/8 "2022-09-05T08:37:39Z")

</div>

The problem was because of incorrect casting to MyCharacter class.

Solution:  
`AMyCharacter * MyCharacterRef = Cast<AMyCharacter>(GetPawn());`
