No announcement yet.

ThirdPersonExample Blueprint vs C++

  • Filter
  • Time
  • Show
Clear All
new posts

    ThirdPersonExample Blueprint vs C++


    I'm just starting UE4. I downloaded the C++ Template "Third Person" and opened it up. I see there is a C++ class that inherits from ACharacter call ThirdPersonCharacter.
    For some reason the template also has a Blueprint with the parent ThirdPersonCharacter, that somehow has a physical entity representation in the game.

    When I go into game mode and inside the gamemode constructor I use
    DefaultPawnClass = ThirdPersonCharacter::Static()

    It will give me the same camera and movement, but the physical representation is gone? Where is the combination of the blueprint and it's parent class?

    I'm confused where that is coming from and how to have that in C++ instead?

    There will most likely be a Blueprint version of the game mode that changes the DefaultPawnClass to the Blueprint version of the ThirdPersonCharacter.

    It is possible to directly reference the Blueprint class, but it requires a bit of extra code and will fail if the Blueprint doesn't exist:
        static ConstructorHelpers::FClassFinder<APawn> BP_ThirdPersonCharacter(TEXT("/Game/Character/BP_ThirdPersonCharacter"));
        DefaultPawnClass = BP_ThirdPersonCharacter.Class;
    If you always spawn without a physical entity representation, you may simply need to change the default game mode to one that includes the third person character:
    Rule#21: Be polite, be professional, but have a plan to kill everyone you meet.


      Thanks, I see the file structure now. It was confusing from the "content" panel. I'm used to just having a real file structure.

      Do you know if I can make the default pawn a c++ class and give it the mesh and other contents? I'm having tons of issues getting the blueprint to update when I change c++ code. I have to remake the entire blueprint typically for each change, which is killing learning the camera functions.


        "Should" be able to modify a good portion of the C++ class a Blueprint is based off without it having any issues unless Blueprintable functions or variables get changed.
        e.g. You rename "USkeletalComponent* Chest" to "USkeletalComponent* Torso".

        What kinds of changes are you making?

        As for the camera functions, you could always separate the camera from the character/pawn entirely by using a PlayerCameraManager.
        Our game uses a true first person, so having decent control of the camera was a must.
        I originally used a camera component on the characters mesh, manually positioned and the like.
        In the end I found using customised player camera manager more to my liking.
        Even when it uses a non-first person view for spectating (or debugging), it still uses the player camera manager just fine.
        It simply creates or removes what ever component it wants to use.
        For example, the over the shoulder view:
        void AGBPlayerCameraManager::UpdateViewTarget(FTViewTarget& OutVT, float DeltaTime)
            if (AGBCharacter* GBCharacter = Cast(OutVT.Target))
                static const FName NAME_ThirdPerson = FName(TEXT("ThirdPerson"));
                static const FName NAME_Fixed = FName(TEXT("Fixed"));
                static const FName NAME_FreeCam = FName(TEXT("FreeCam"));
                static const FName NAME_FixedFollow = FName(TEXT("FixedFollow"));
                static const FName NAME_OverTheShoulder = FName(TEXT("OTS"));
                OutVT.POV.FOV = GBCharacter->GetPlayerFOV(EPlayerFOV::Default);
                // If the camera style change, reset anything that needs resetting.
                if (CameraStyle != OldCameraStyle)
                if ((CameraStyle == NAME_Fixed) || (CameraStyle == NAME_FixedFollow))
                    UpdateFixedView(GBCharacter, OrigPOV, OutVT.POV);
                else if (CameraStyle == NAME_OverTheShoulder)
                    UpdateOverTheShoulderView(GBCharacter, DeltaTime, OutVT.POV);
                else if (CameraStyle == NAME_ThirdPerson)
        void AGBPlayerCameraManager::UpdateOverTheShoulderView(AGBCharacter* GBCharacter, float DeltaTime, FMinimalViewInfo& OutPOV)
            USpringArmComponent* CameraBoom = GBCharacter->FindComponentByClass();
            if (CameraBoom == nullptr)
                CameraBoom = NewObject(GBCharacter);
                CameraBoom->AttachToComponent(GBCharacter->GetMesh(), FAttachmentTransformRules::SnapToTargetIncludingScale, GBCharacter->GetEyesSocket());
                CameraBoom->bUsePawnControlRotation = true;
                CameraBoom->bEnableCameraLag = true;
                CameraBoom->CameraLagMaxDistance = 32.0f;
                CameraBoom->bEnableCameraRotationLag = true;
            CameraBoom->TargetArmLength = ShoulderCamDistance;
            FVector TargetSocketOffset = ShoulderCamOffset;
            if (GBCharacter->WantsToLeanLeft())
                TargetSocketOffset.Y *= -1.0f;
            CameraBoom->SocketOffset = FMath::VInterpTo(CameraBoom->SocketOffset, TargetSocketOffset, DeltaTime, 5.0f);
            const FTransform CameraBoomTM = CameraBoom->GetSocketTransform(NAME_None);
            OutPOV.Location = CameraBoomTM.GetLocation();
            OutPOV.Rotation = CameraBoomTM.GetRotation().Rotator();
        If you prefer C++, it might be worth considering
        Rule#21: Be polite, be professional, but have a plan to kill everyone you meet.