From 01aeecf953685798eac0b48eff6dd6bdf661179c Mon Sep 17 00:00:00 2001 From: baz Date: Thu, 4 Jan 2024 15:50:15 +0000 Subject: [PATCH] Replace default CharacterMovementComponent with NakatomiCMC --- Source/Nakatomi/EnemyCharacter.cpp | 2 +- Source/Nakatomi/EnemyCharacter.h | 2 +- Source/Nakatomi/NakatomiCharacter.cpp | 7 ++++++- Source/Nakatomi/NakatomiCharacter.h | 8 +++++++- Source/Nakatomi/PlayerCharacter.cpp | 2 +- Source/Nakatomi/PlayerCharacter.h | 6 +++++- 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Source/Nakatomi/EnemyCharacter.cpp b/Source/Nakatomi/EnemyCharacter.cpp index c7b5d01..4a90cc3 100644 --- a/Source/Nakatomi/EnemyCharacter.cpp +++ b/Source/Nakatomi/EnemyCharacter.cpp @@ -5,7 +5,7 @@ #define COLLISION_WEAPON ECC_GameTraceChannel1 -AEnemyCharacter::AEnemyCharacter() +AEnemyCharacter::AEnemyCharacter(const FObjectInitializer& ObjectInitializer) : ANakatomiCharacter(ObjectInitializer) { RandomWeaponParameters = CreateDefaultSubobject(TEXT("Random Weapon Parameters")); diff --git a/Source/Nakatomi/EnemyCharacter.h b/Source/Nakatomi/EnemyCharacter.h index 6bd79fe..4f32743 100644 --- a/Source/Nakatomi/EnemyCharacter.h +++ b/Source/Nakatomi/EnemyCharacter.h @@ -27,7 +27,7 @@ private: FTimerHandle CooldownTimerHandle; public: - AEnemyCharacter(); + AEnemyCharacter(const FObjectInitializer& ObjectInitializer); UBehaviorTree* GetBehaviourTree(); diff --git a/Source/Nakatomi/NakatomiCharacter.cpp b/Source/Nakatomi/NakatomiCharacter.cpp index 9c2afdd..c60e675 100644 --- a/Source/Nakatomi/NakatomiCharacter.cpp +++ b/Source/Nakatomi/NakatomiCharacter.cpp @@ -3,12 +3,17 @@ #include "NakatomiCharacter.h" +#include "NakatomiCMC.h" + // Sets default values -ANakatomiCharacter::ANakatomiCharacter() +ANakatomiCharacter::ANakatomiCharacter(const FObjectInitializer& ObjectInitializer) : Super( + ObjectInitializer.SetDefaultSubobjectClass(ACharacter::CharacterMovementComponentName)) { // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; + NakatomiCMC = Cast(GetCharacterMovement()); + HealthComponent = CreateDefaultSubobject(TEXT("Health Component")); HealthComponent->OnDamaged.BindUFunction(this, "OnDamaged"); HealthComponent->OnDeath.BindUFunction(this, "OnDeath"); diff --git a/Source/Nakatomi/NakatomiCharacter.h b/Source/Nakatomi/NakatomiCharacter.h index 0c368f1..3aa1a0d 100644 --- a/Source/Nakatomi/NakatomiCharacter.h +++ b/Source/Nakatomi/NakatomiCharacter.h @@ -5,6 +5,7 @@ #include "CoreMinimal.h" #include "GameFramework/Character.h" #include "HealthComponent.h" +#include "NakatomiCMC.h" #include "Throwable.h" #include "Weapon.h" #include "NakatomiCharacter.generated.h" @@ -38,6 +39,10 @@ public: UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) TArray> ThrowableInventory; +protected: + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Meta = (AllowPrivateAccess = "true")) + UNakatomiCMC* NakatomiCMC; + private: UPROPERTY(VisibleDefaultsOnly) UHealthComponent* HealthComponent = nullptr; @@ -47,9 +52,10 @@ private: UPROPERTY(EditDefaultsOnly) int MaximumThrowableInventorySize = 4; + public: // Sets default values for this character's properties - ANakatomiCharacter(); + ANakatomiCharacter(const FObjectInitializer& ObjectInitializer); protected: // Called when the game starts or when spawned diff --git a/Source/Nakatomi/PlayerCharacter.cpp b/Source/Nakatomi/PlayerCharacter.cpp index 1ce9d3d..5e8e4fb 100644 --- a/Source/Nakatomi/PlayerCharacter.cpp +++ b/Source/Nakatomi/PlayerCharacter.cpp @@ -19,7 +19,7 @@ #define COLLISION_WEAPON ECC_GameTraceChannel1 // Sets default values -APlayerCharacter::APlayerCharacter() +APlayerCharacter::APlayerCharacter(const FObjectInitializer& ObjectInitializer) : ANakatomiCharacter(ObjectInitializer) { // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; diff --git a/Source/Nakatomi/PlayerCharacter.h b/Source/Nakatomi/PlayerCharacter.h index 7d4323d..7507789 100644 --- a/Source/Nakatomi/PlayerCharacter.h +++ b/Source/Nakatomi/PlayerCharacter.h @@ -14,6 +14,7 @@ #include "Blueprint/UserWidget.h" #include "Perception/AIPerceptionStimuliSourceComponent.h" #include "InteractableComponent.h" +#include "NakatomiCMC.h" #include "Throwable.h" #include "PlayerCharacter.generated.h" @@ -95,6 +96,9 @@ protected: float DefaultAimSensitivity = 45.0f; private: + // UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Meta = (AllowPrivateAccess = "true")) + // UNakatomiCMC* NakatomiCMC; + UPROPERTY(EditAnywhere, BlueprintReadWrite, Meta = (AllowPrivateAccess = "true")) USpringArmComponent* CameraSpringArmComponent = nullptr; @@ -132,7 +136,7 @@ private: public: // Sets default values for this character's properties - APlayerCharacter(); + APlayerCharacter(const FObjectInitializer& ObjectInitializer); protected: // Called when the game starts or when spawned