기본 Character의 구성요소는 Character class에 선언되어 있는 private 파트에서 확인할 수 있다.
// Character.cpp
private:
/** The main skeletal mesh associated with this Character (optional sub-object). */
UPROPERTY(Category=Character, VisibleAnywhere, BlueprintReadOnly, meta=(AllowPrivateAccess = "true"))
TObjectPtr<USkeletalMeshComponent> Mesh;
/** Movement component used for movement logic in various movement modes (walking, falling, etc), containing relevant settings and functions to control movement. */
UPROPERTY(Category=Character, VisibleAnywhere, BlueprintReadOnly, meta=(AllowPrivateAccess = "true"))
TObjectPtr<UCharacterMovementComponent> CharacterMovement;
/** The CapsuleComponent being used for movement collision (by CharacterMovement). Always treated as being vertically aligned in simple collision check functions. */
UPROPERTY(Category=Character, VisibleAnywhere, BlueprintReadOnly, meta=(AllowPrivateAccess = "true"))
TObjectPtr<UCapsuleComponent> CapsuleComponent;
#if WITH_EDITORONLY_DATA
/** Component shown in the editor only to indicate character facing */
UPROPERTY()
TObjectPtr<UArrowComponent> ArrowComponent;
#endif
각 Component에 대한 Getter 함수들은 아래에서 확인할 수 있다.
// Character.cpp
public:
/** Returns Mesh subobject **/
FORCEINLINE class USkeletalMeshComponent* GetMesh() const { return Mesh; }
/** Name of the MeshComponent. Use this name if you want to prevent creation of the component (with ObjectInitializer.DoNotCreateDefaultSubobject). */
static FName MeshComponentName;
/** Returns CharacterMovement subobject **/
template <class T>
FORCEINLINE_DEBUGGABLE T* GetCharacterMovement() const
{
return CastChecked<T>(CharacterMovement, ECastCheckedType::NullAllowed);
}
FORCEINLINE UCharacterMovementComponent* GetCharacterMovement() const { return CharacterMovement; }
/** Name of the CharacterMovement component. Use this name if you want to use a different class (with ObjectInitializer.SetDefaultSubobjectClass). */
static FName CharacterMovementComponentName;
/** Returns CapsuleComponent subobject **/
FORCEINLINE class UCapsuleComponent* GetCapsuleComponent() const { return CapsuleComponent; }
/** Name of the CapsuleComponent. */
static FName CapsuleComponentName;
#if WITH_EDITORONLY_DATA
/** Returns ArrowComponent subobject **/
class UArrowComponent* GetArrowComponent() const { return ArrowComponent; }
#endif
/** Sets the component the Character is walking on, used by CharacterMovement walking movement to be able to follow dynamic objects. */
virtual void SetBase(UPrimitiveComponent* NewBase, const FName BoneName = NAME_None, bool bNotifyActor=true);
CharacterBase가 이렇게 구성되어 있다는 것을 알면 이제, Character class를 상속하는 class들은 GetCapsuleComponent(), GetCharacterMovement(), GetMesh()의 함수들을 통해 Character Component들에 접근할 수 있다.
// Fill out your copyright notice in the Description page of Project Settings.
#include "Character/ABCharacterBase.h"
#include "Components/CapsuleComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
// Sets default values
AABCharacterBase::AABCharacterBase()
{
// Pawn
bUseControllerRotationPitch = false;
bUseControllerRotationYaw = false;
bUseControllerRotationRoll = false;
// Capsule
GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);
GetCapsuleComponent()->SetCollisionProfileName(TEXT("Pawn"));
// Movement
GetCharacterMovement()->bOrientRotationToMovement = true;
GetCharacterMovement()->RotationRate = FRotator(0.0f, 500.0f, 0.0f);
GetCharacterMovement()->JumpZVelocity = 700.f;
GetCharacterMovement()->AirControl = 0.35f;
GetCharacterMovement()->MaxWalkSpeed = 500.f;
GetCharacterMovement()->MinAnalogWalkSpeed = 20.f;
GetCharacterMovement()->BrakingDecelerationWalking = 2000.f;
// Mesh
GetMesh()->SetRelativeLocationAndRotation(FVector(0.0f, 0.0f, -100.0f), FRotator(0.0f, -90.0f, 0.0f));
GetMesh()->SetAnimationMode(EAnimationMode::AnimationBlueprint);
GetMesh()->SetCollisionProfileName(TEXT("CharacterMesh"));
static ConstructorHelpers::FObjectFinder<USkeletalMesh> CharacterMeshRef(TEXT("/Script/Engine.SkeletalMesh'/Game/Characters/Mannequins/Meshes/SKM_Quinn_Simple.SKM_Quinn_Simple'"));
if (CharacterMeshRef.Object)
{
GetMesh()->SetSkeletalMesh(CharacterMeshRef.Object);
}
static ConstructorHelpers::FClassFinder<UAnimInstance> AnimInstanceClassRef(TEXT("/Game/Characters/Mannequins/Animations/ABP_Quinn.ABP_Quinn_C"));
if (AnimInstanceClassRef.Class)
{
GetMesh()->SetAnimInstanceClass(AnimInstanceClassRef.Class);
}
}