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((), 0));
if (GetPawn()->GetClass() == BP_Ball1)
{
GetPawn()->Destroy();
UnPossess();
UWorld* const World = ();
//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 = ();
//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.