ACharacter::ACharacter(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
// Structure to hold one-time initialization
struct FConstructorStatics
{
FName ID_Characters;
FText NAME_Characters;
FConstructorStatics()
: ID_Characters(TEXT("Characters"))
, NAME_Characters(NSLOCTEXT("SpriteCategory", "Characters", "Characters"))
{
}
};
static FConstructorStatics ConstructorStatics;
// Character rotation only changes in Yaw, to prevent the capsule from changing orientation.
// Ask the Controller for the full rotation if desired (ie for aiming).
bUseControllerRotationPitch = false;
bUseControllerRotationRoll = false;
bUseControllerRotationYaw = true;
CapsuleComponent = CreateDefaultSubobject<UCapsuleComponent>(ACharacter::CapsuleComponentName);
CapsuleComponent->InitCapsuleSize(34.0f, 88.0f);
CapsuleComponent->SetCollisionProfileName(UCollisionProfile::Pawn_ProfileName);
CapsuleComponent->CanCharacterStepUpOn = ECB_No;
CapsuleComponent->SetShouldUpdatePhysicsVolume(true);
CapsuleComponent->SetCanEverAffectNavigation(false);
CapsuleComponent->bDynamicObstacle = true;
RootComponent = CapsuleComponent;
bClientCheckEncroachmentOnNetUpdate = true;
JumpKeyHoldTime = 0.0f;
JumpMaxHoldTime = 0.0f;
JumpMaxCount = 1;
JumpCurrentCount = 0;
JumpCurrentCountPreJump = 0;
bWasJumping = false;
AnimRootMotionTranslationScale = 1.0f;
#if WITH_EDITORONLY_DATA
ArrowComponent = CreateEditorOnlyDefaultSubobject<UArrowComponent>(TEXT("Arrow"));
if (ArrowComponent)
{
ArrowComponent->ArrowColor = FColor(150, 200, 255);
ArrowComponent->bTreatAsASprite = true;
ArrowComponent->SpriteInfo.Category = ConstructorStatics.ID_Characters;
ArrowComponent->SpriteInfo.DisplayName = ConstructorStatics.NAME_Characters;
ArrowComponent->SetupAttachment(CapsuleComponent);
ArrowComponent->bIsScreenSizeScaled = true;
}
#endif // WITH_EDITORONLY_DATA
CharacterMovement = CreateDefaultSubobject<UCharacterMovementComponent>(ACharacter::CharacterMovementComponentName);
if (CharacterMovement)
{
CharacterMovement->UpdatedComponent = CapsuleComponent;
CrouchedEyeHeight = CharacterMovement->CrouchedHalfHeight * 0.80f;
}
Mesh = CreateOptionalDefaultSubobject<USkeletalMeshComponent>(ACharacter::MeshComponentName);
if (Mesh)
{
Mesh->AlwaysLoadOnClient = true;
Mesh->AlwaysLoadOnServer = true;
Mesh->bOwnerNoSee = false;
Mesh->VisibilityBasedAnimTickOption = EVisibilityBasedAnimTickOption::AlwaysTickPose;
Mesh->bCastDynamicShadow = true;
Mesh->bAffectDynamicIndirectLighting = true;
Mesh->PrimaryComponentTick.TickGroup = TG_PrePhysics;
Mesh->SetupAttachment(CapsuleComponent);
static FName MeshCollisionProfileName(TEXT("CharacterMesh"));
Mesh->SetCollisionProfileName(MeshCollisionProfileName);
Mesh->SetGenerateOverlapEvents(false);
Mesh->SetCanEverAffectNavigation(false);
}
BaseRotationOffset = FQuat::Identity;
}
1 Like