Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to change default camera to CameraComponent

Hi, I have following problem, I create CameraComponent in my base C++ class for Character

 // Sets default values
      // Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
     PrimaryActorTick.bCanEverTick = true;
     defaultMovementSpeed = 600.0f;
     pCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("ActualCamera"));
 // Called when the game starts or when spawned
 void ADefaultCharacter::BeginPlay()
     if (pCamera) {
         pCamera->SetWorldLocation(FVector(-900, 100, 100));
         APlayerController *pContr = GetWorld()->GetFirstPlayerController();
         if (pContr) {

So far everything looks good - the component is created and assigned to object. Now comes the tricky part. When I start game I can see there is some default camera created alt text

Now whenever my character moves I see camera standing still in place. But as I said, there is also CameraComponent in my Character alt text

And after I click on DefaultCharacterBP40 the camera switches and now it is following the Character.

Question - how do I make that switch from the very beggining? I want my default Camera to be the one from CameraComponent. And how do I remove this one automaticaly added camera?

Product Version: UE 4.10 Preview
1.png (27.9 kB)
2.png (122.8 kB)
more ▼

asked Oct 26 '15 at 08:12 PM in C++ Programming

avatar image

1 1 2 3

avatar image Doug E ♦♦ STAFF Oct 26 '15 at 09:39 PM

Hey Dragin-

I'm not sure I'm seeing the same result that you're describing. I copied the code posted above into a custom Character class and created a BP of that class. When I set MyCharBP as the default pawn and play in editor the camera is located at the world origin. Could you post the full code for the character class so that I can make sure I'm following the same setup?

One thing that might help would be to attach the camera to another component (RootComponent/Mesh/SpringArm) so that the camera updates when its parent updates. Also, let me know if you have your custom character set to the default pawn inside the world settings.


Doug Wilson

avatar image Dragin Oct 26 '15 at 10:55 PM

That is actually the full code, just header with declarations of functions and camera variable, nothing special. But maybe some more explaination of how I set everything. So I have two lvls, both using different GameModes. The first one is kind of "menu" lvl and is supposed to load 2nd world. The 2nd has blueprint GameMode which base class is in C++, I have also custom HUD class and player controller. There is also CameraManager class. Default Pawn Class is set to "none" because I am spawning it via C++ code from GameMode.

 AMainGameMode::AMainGameMode() {
     static ConstructorHelpers::FObjectFinder<UClass> ItemBlueprint(TEXT("Class'/Game/DefaultCharacterBP.DefaultCharacterBP_C'"));
     if (ItemBlueprint.Object) {
         DefaultCharacterHandle = (UClass*)ItemBlueprint.Object;
 void AMainGameMode::BeginPlay()
     UWorld* const World = GetWorld();
     if (World) {
         DefaultCharacter = World->SpawnActor<ADefaultCharacter>(DefaultCharacterHandle);
         if (DefaultCharacter) {
             DebugLog("Character Spawned");
             DefaultCharacter->SetActorLocation(FVector(-900, 100, 40));

 AMainPlayerController::AMainPlayerController() {
     bAutoManageActiveCameraTarget = false;
     PlayerCameraManagerClass = AMainPlayerCameraManager::StaticClass();

Other things (like my custom CameraManager) isn't modified, just created and not modified.

avatar image Doug E ♦♦ STAFF Oct 27 '15 at 02:01 PM

When you start playing is the game view through the correct camera setup through the character or are you "looking" through the other camera that shows in the world outliner? If possible could you take a short video of what you're seeing to help me visualize what's happening.

Additionally, you may want to consider narrowing down what is returned to ItemBlueprint if you are trying to reference your character blueprint. With it set as a UClass it could return anything, instead it would be better to use APawn to ensure that the class it finds is a child of pawn (which characters are).

avatar image Dragin Oct 27 '15 at 08:14 PM

Here is the video. https://youtu.be/1wyvUzel_do

avatar image Doug E ♦♦ STAFF Oct 28 '15 at 03:12 PM

On the BeginPlay for your character you can try calling [cameraComponent]->Activate(); to hopefully force your camera to be the primary. If that doesn't work could you upload your project to dropbox and send me a link to download it. So far I've not had the same issue you're seeing when starting the game and would like to test your problem directly.


Doug Wilson

avatar image Dragin Oct 28 '15 at 07:12 PM
avatar image Doug E ♦♦ STAFF Oct 30 '15 at 03:37 PM

I tested the project you linked and did not have the same behavior shown in your video. When I click the "Start Game" button and the level changes, the camera is attached to the actor as expect and will follow along with my movement inputs. I had noticed that in the code your pCamera is not set as a UPROPERTY() . The Spring Arm defined in code is also not being used. It may help to look at the Third Person Template character blueprint. There the SpringArm and Camera are added through the editor rather than defined in code (note that the "(inherited)" label is missing in the component list).

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Hi Dragin,

We have not heard back from you in a few days, so we are marking this post as Resolved for tracking purposes. If you are still experiencing the issue you reported, please respond to this message with additional information and we will offer further assistance.

Thank you.

more ▼

answered Nov 03 '15 at 09:05 PM

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

You didn't attach the Camera to your actor.

 pCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("ActualCamera"));
 pCamera->AttachParent = RootComponent;

And if you just want to change your view target you can use SetViewTargetWithBlend


more ▼

answered Oct 28 '15 at 03:21 PM

avatar image

1.9k 60 50 190

avatar image Dragin Oct 28 '15 at 06:05 PM

pCamera->AttachParent = RootComponent; Didn't help

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question