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"

Using a PlayerCameraManager to keep a same camera while changing Pawns

Hello, I have made rolling balls pawns using the Rolling Ball default template, except the camera works slightly differently. It follows the movements of the mouse. I'd like to separate the camera from the pawns entirely using a player camera manager, In such a way that a camera is always following whichever pawn is presently controlled by the player controller. With my present system, when I switch pawns, the old pawn and its camera is destroyed, and the new pawn and its camera are then spawned, resetting the camera.

I have had trouble finding information and examples of how to use a player camera manager.

Here is the PlayerController code used to switch pawns. Also, the two pawns are different blueprints of a same class.

ReptilePlayerController.cpp

 AReptilePlayerController::AReptilePlayerController(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
 {
     static ConstructorHelpers::FObjectFinder<UBlueprint> Ball1(TEXT("Blueprint'/Game/RelevantContent/BP_RollingPawn.BP_RollingPawn'"));
     if (Ball1.Object) {
         BP_Ball1 = (UClass*)Ball1.Object->GeneratedClass;
     }
     static ConstructorHelpers::FObjectFinder<UBlueprint> Ball2(TEXT("Blueprint'/Game/RelevantContent/BP_RollingPawn2.BP_RollingPawn2'"));
     if (Ball2.Object) {
         BP_Ball2 = (UClass*)Ball2.Object->GeneratedClass;
     }
 }
 
 void AReptilePlayerController::SetupInputComponent()
 {
     Super::SetupInputComponent();
 
     InputComponent->BindAction("Morph", IE_Pressed, this, &AReptilePlayerController::Morph);
 }
 
 void AReptilePlayerController::Morph()
 {
     //References to our different morphs
     GEngine->AddOnScreenDebugMessage(2, 2, FColor::White, "Morph!");
 
     //We destroy our pawn and unpossess it
     FVector position = GetPawn()->GetActorLocation();
     FRotator orientation = GetPawn()->GetActorRotation();
 
     ARollingPawn *player = Cast<ARollingPawn>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0));
 
     if (GetPawn()->GetClass() == BP_Ball1)
     {
         GetPawn()->Destroy();
         UnPossess();
 
         UWorld* const World = GetWorld();
 
         //Now we spawn the other one and possess it.
         ARollingPawn* Roller = World->SpawnActor<ARollingPawn>(BP_Ball2, position, orientation);
         Possess(Roller);
     }
 
     else if (GetPawn()->GetClass() == BP_Ball2)
     {
         GetPawn()->Destroy();
         UnPossess();
 
         UWorld* const World = GetWorld();
 
         //Now we spawn the other one and possess it.
         ARollingPawn* Roller = World->SpawnActor<ARollingPawn>(BP_Ball1, position, orientation);
         Possess(Roller);
     }
 }



ReptilePlayerController.h

 UCLASS()
 class GETTINGSERIOUS_API AReptilePlayerController : public APlayerController
 {
     GENERATED_BODY()
     
 public:
         
     AReptilePlayerController(const FObjectInitializer& ObjectInitializer);
 
     virtual void SetupInputComponent() override;
     
     //Function to change shape
     void Morph();
 
     TSubclassOf<ARollingPawn> BP_Ball1;
     TSubclassOf<ARollingPawn> BP_Ball2;
 
 };


Anyone knows how to work with Camera Managers? Thanks in advance! Please, don't hesitate to ask me for more details if I forgot something important.

Product Version: UE 4.8
Tags:
more ▼

asked Jun 20 '15 at 12:25 AM in C++ Programming

avatar image

Xylord
41 9 14 16

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

1 answer: sort voted first

There no need call anything in PlayerCameraManager, you can just use PlayerController. First you need to set bAutoManageActiveCameraTarget to false in player controller, so possession wont automatically set view target, then you call SetViewTarget(Actor) and argument Actor becomes view target. Normally with variable i mentioned said to true, possessed Pawn becomes view target.

View target is a actor that is viewed in camera and each actor can have it's own camera setup. When Actor is view target, PlayerCameraManager asks that actor for camera positioning on every frame, by calling CalcCamera which has struct as a argument in which set camera position in (you don't return anything):

https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/GameFramework/AActor/CalcCamera/index.html

Default code in CalcCamera, picks first found camera component and apply position of that component as a camera. Also there no point of calling Super::CalcCamera here ofcorse

more ▼

answered Jun 20 '15 at 01:49 AM

avatar image

Shadowriver
36.6k 932 169 1111

avatar image Xylord Jun 20 '15 at 11:44 PM

That's very helpful, thank you!

I managed set boolean you mentioned to false, and used SetViewActor in my PlayerController, so that I had SetViewActor(GetPawn);. However, I'm not sure how I can change the camera setup of view target. Is it a blueprint, or settings that I modify in my cpp class?

What would a usage of CalcCamera look like?

 void AReptilePlayerController::Tick(float DeltaTime)
 {
     Super::Tick(DeltaTime);
 
     FMinimalViewInfo* CameraSetup;
         
     Cast<FMinimalViewInfo>(CameraSetup)->Location = FVector(0, 0, 0);
     Cast<FMinimalViewInfo>(CameraSetup)->Rotation = FRotator(0, 0, 0);
 
     CalcCamera(DeltaTime, CameraSetup);
 
 }

Would it be something like that?

avatar image Shadowriver Jun 22 '15 at 03:37 PM

I said PlayerCameraMenager calls CameraCalc, so obviuesly you need to override CameraCalc. Here you have have default setup which fiunds camera component and set camera position in to it:

 void AActor::CalcCamera(float DeltaTime, FMinimalViewInfo& OutResult)
 {
     if (bFindCameraComponentWhenViewTarget)
     {
         // Look for the first active camera component and use that for the view
         TInlineComponentArray<UCameraComponent*> Cameras;
         GetComponents<UCameraComponent>(/*out*/ Cameras);
 
         for (UCameraComponent* CameraComponent : Cameras)
         {
             if (CameraComponent->bIsActive)
             {
                 CameraComponent->GetCameraView(DeltaTime, OutResult);
                 return;
             }
         }
     }
 
     GetActorEyesViewPoint(OutResult.Location, OutResult.Rotation);
 } 
avatar image Xylord Jun 22 '15 at 10:25 PM

Thanks for being patient with me :)

I think I get a bit more how CalcCamera works now.

I now use camera linked to the controller instead of one linked to the pawns, which is great. However, I struggle with modifying the camera setup from outside of the CameraCalc function. Right, I've this :

ReptilePlayerController.cpp

 void AReptilePlayerController::CalcCamera(float DeltaTime, struct FMinimalViewInfo& OutResult)
 {
     FVector boom;
 
     FVector 
 
     boom = FVector(-200, 0, 20);
 
     OutResult.Location = GetPawn()->GetActorLocation() + boom;
     OutResult.Rotation = FRotator(0, 10, 0);
     
 }

This places the camera behind my pawn, and when I switch pawns, it stays right there, while still following it when it moves around! Exactly what I want basically as far as this goes. But if say I want to pitch the camera from a separate function, how can I change the equivalent of OutResult (in CalcCamera) from there?

(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