From e06b1738c29297270a92c3887535d2bb71795f61 Mon Sep 17 00:00:00 2001 From: baz Date: Wed, 12 Jun 2024 21:35:12 +0100 Subject: [PATCH] Move HealthComponent to base Character class --- Source/vampires/PlayerCharacter.cpp | 3 --- Source/vampires/PlayerCharacter.h | 3 --- Source/vampires/VampireCharacter.cpp | 2 ++ Source/vampires/VampireCharacter.h | 6 ++++++ 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Source/vampires/PlayerCharacter.cpp b/Source/vampires/PlayerCharacter.cpp index 7f78c2a..5b51953 100644 --- a/Source/vampires/PlayerCharacter.cpp +++ b/Source/vampires/PlayerCharacter.cpp @@ -27,9 +27,6 @@ APlayerCharacter::APlayerCharacter() CameraComponent->SetProjectionMode(ECameraProjectionMode::Type::Orthographic); CameraComponent->SetOrthoWidth(4000.0f); - // Create Health Component - HealthComponent = CreateDefaultSubobject(TEXT("Health Component")); - // Create EXP Component EXPComponent = CreateDefaultSubobject(TEXT("EXP Component")); } diff --git a/Source/vampires/PlayerCharacter.h b/Source/vampires/PlayerCharacter.h index 294bbd1..e8bfc18 100644 --- a/Source/vampires/PlayerCharacter.h +++ b/Source/vampires/PlayerCharacter.h @@ -4,7 +4,6 @@ #include "CoreMinimal.h" #include "EXPComponent.h" -#include "HealthComponent.h" #include "VampireCharacter.h" #include "Camera/CameraComponent.h" #include "GameFramework/SpringArmComponent.h" @@ -35,8 +34,6 @@ public: UInputAction* MovementAction; protected: - UPROPERTY() - UHealthComponent* HealthComponent; UPROPERTY() UEXPComponent* EXPComponent; diff --git a/Source/vampires/VampireCharacter.cpp b/Source/vampires/VampireCharacter.cpp index 219bd69..a3b34d8 100644 --- a/Source/vampires/VampireCharacter.cpp +++ b/Source/vampires/VampireCharacter.cpp @@ -9,6 +9,8 @@ AVampireCharacter::AVampireCharacter() // 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; + // Create Health Component + HealthComponent = CreateDefaultSubobject(TEXT("Health Component")); } // Called when the game starts or when spawned diff --git a/Source/vampires/VampireCharacter.h b/Source/vampires/VampireCharacter.h index 55ed825..ba02b05 100644 --- a/Source/vampires/VampireCharacter.h +++ b/Source/vampires/VampireCharacter.h @@ -4,6 +4,7 @@ #include "CoreMinimal.h" #include "GameFramework/Character.h" +#include "HealthComponent.h" #include "VampireCharacter.generated.h" UCLASS() @@ -11,6 +12,11 @@ class VAMPIRES_API AVampireCharacter : public ACharacter { GENERATED_BODY() +protected: + + UPROPERTY() + UHealthComponent* HealthComponent; + public: // Sets default values for this character's properties AVampireCharacter();