x

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"

Set up a camera insider player controller

I lost a few days already and can't understand it so far, nothing works ! I create the SpringArm and the camera in the contructor, and then I override the Possess function, and try to attach the arm and camera to pawn->GetRootComponent();

Nothing works so far ! Could someone explain it to me ? Or is this even needed, maybe there is a workaround, I was thinking of putting all the controller logic in controller so I could posses any type of character in game, without needing to implements all the camera and spring arm in each on of those. I took the top down project, copied everything from character contrstructor to controller contructor, left only attachment in posses:

 void ATestPlayerController::Possess(APawn* InPawn)
 {
     Super::Possess(InPawn);
 
         if(InPawn)
         {
             CameraBoom->AttachTo(InPawn->GetRootComponent());
             TopDownCameraComponent->AttachTo(CameraBoom, USpringArmComponent::SocketName);
         }
 }

Nothing. then I tried something like this:

 void ATestPlayerController::Possess(APawn* InPawn)
 {
     Super::Possess(InPawn);
 
         if(InPawn)
         {
             CameraBoom = NewObject<USpringArmComponent>(this, USpringArmComponent::StaticClass());
             CameraBoom->RegisterComponent();
             CameraBoom->AttachTo(InPawn->GetRootComponent());
             CameraBoom->bAbsoluteRotation = true; // Don't want arm to rotate when character does
             CameraBoom->TargetArmLength = 800.f;
             CameraBoom->RelativeRotation = FRotator(-60.f, 0.f, 0.f);
             CameraBoom->bDoCollisionTest = false; // Don't want to pull camera in when it collides with level
 
             // Create a camera...
             TopDownCameraComponent = NewObject<UCameraComponent>(this, UCameraComponent::StaticClass());
             TopDownCameraComponent->RegisterComponent();
             TopDownCameraComponent->AttachTo(CameraBoom, USpringArmComponent::SocketName);
             TopDownCameraComponent->bUsePawnControlRotation = false;
         }
 }
Product Version: Not Selected
Tags:
more ▼

asked Sep 15 '15 at 06:04 PM in C++ Programming

avatar image

IHateGlamour
3 2 4 6

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

1 answer: sort voted first

When you possess the pawn becomes view target, camera system then searches view target for camera component inside the view target pawn. But because you creating components in controller, camera component is registered in controller not in your Pawn and camera system don't see camera component. You should set up camera component in pawn, when you possess pawn it becomes view target and that actor manages camera which by default follows camera component inside actor.

You can change that behavior if you wish, i explained how camera system works in UE4 many times so instead of typing this over and over again i will simply paste a link from other question (but it seems you find it already ^^):

https://answers.unrealengine.com/questions/293298/attaching-camera-to-pawn-at-runtime.html

more ▼

answered Sep 15 '15 at 08:04 PM

avatar image

Shadowriver
36.6k 932 169 1111

avatar image IHateGlamour Sep 15 '15 at 09:49 PM

Problem being that if I want to implement something like mind control, I need to implement a camera and a spring arm for each of the existing character in game, that doesn't seems that good.. I saw your earlier comments on that, and I tried looking through all those things and unreal source, but at this point it is to much to grasp :)

Thanks for explanation, things are now a bit easier to understand. You're sure the object is registered to controller in RegisterComponent ? I will look tomorrow more into it. Would changing this help:

 CameraBoom = NewObject<USpringArmComponent>(InPawn, USpringArmComponent::StaticClass());

Or is there a way to register a component into a different object. Maybe even something crazy like making an interface:

 //  Called from controller to register into the character
 MyCharacter->Register(USpringArmComponent* arm);

I don't know, just tired and a lot of crazy ideas...

Anyway, thanks for your help :)

avatar image IHateGlamour Sep 16 '15 at 04:54 AM

It worked!

 CameraBoom = NewObject<USpringArmComponent>(InPawn, TEXT("CameraBoom"));

It seems that the owned Actor is set here, but not in RegisterComponent, and finally it works ! And the "Outer object" is simply the owner of the created Object ?

I still have a question, I am building onto the TopDown template, and the spring arm with the camera won't rotate into position until I click to move the character.

avatar image Shadowriver Sep 16 '15 at 03:38 PM

Then declere camera components in base class of pawn that can be mind controlled, or for all characters overall. You really don't need to do that dynamicly

Check if there some code in TopDown character that might be involved

(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