From 40e5a37d9129d88fa4f26f5a9da3b0db287e559f Mon Sep 17 00:00:00 2001 From: Foxim Date: Fri, 21 Feb 2025 15:59:46 +0100 Subject: [PATCH] fix: correct player character check add player attribute component test class --- .../ExoPlayerAttributesComponent.cpp | 34 +++++++++++++++++++ .../Private/Player/ExoPlayerController.cpp | 8 +++-- .../Components/ExoPlayerAttributesComponent.h | 28 +++++++++++++++ .../Exo/Public/Player/ExoPlayerController.h | 3 +- 4 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 Source/Exo/Private/Characters/Components/ExoPlayerAttributesComponent.cpp create mode 100644 Source/Exo/Public/Characters/Components/ExoPlayerAttributesComponent.h diff --git a/Source/Exo/Private/Characters/Components/ExoPlayerAttributesComponent.cpp b/Source/Exo/Private/Characters/Components/ExoPlayerAttributesComponent.cpp new file mode 100644 index 0000000..62822c8 --- /dev/null +++ b/Source/Exo/Private/Characters/Components/ExoPlayerAttributesComponent.cpp @@ -0,0 +1,34 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Characters/Components/ExoPlayerAttributesComponent.h" + +// Sets default values for this component's properties +UExoPlayerAttributesComponent::UExoPlayerAttributesComponent() +{ + // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features + // off to improve performance if you don't need them. + PrimaryComponentTick.bCanEverTick = true; + + // ... +} + + +// Called when the game starts +void UExoPlayerAttributesComponent::BeginPlay() +{ + Super::BeginPlay(); + + // ... + +} + + +// Called every frame +void UExoPlayerAttributesComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + + // ... +} + diff --git a/Source/Exo/Private/Player/ExoPlayerController.cpp b/Source/Exo/Private/Player/ExoPlayerController.cpp index 1891fae..7417f9d 100644 --- a/Source/Exo/Private/Player/ExoPlayerController.cpp +++ b/Source/Exo/Private/Player/ExoPlayerController.cpp @@ -4,6 +4,7 @@ #include "Player/ExoPlayerController.h" #include "EnhancedInputComponent.h" #include "EnhancedInputSubsystems.h" +#include "Characters/ExoPlayerCharacter.h" #include "GameFramework/Character.h" #include "GameFramework/CharacterMovementComponent.h" @@ -17,15 +18,16 @@ void AExoPlayerController::BeginPlay() Super::BeginPlay(); check(InputContext); + PlayerCharacter = Cast(GetPawn()); + check(PlayerCharacter); + UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem(GetLocalPlayer()); if (Subsystem) { Subsystem->AddMappingContext(InputContext, 0); } - - PlayerCharacter = GetPawn(); - + InteractionComponent = PlayerCharacter->FindComponentByClass(); } diff --git a/Source/Exo/Public/Characters/Components/ExoPlayerAttributesComponent.h b/Source/Exo/Public/Characters/Components/ExoPlayerAttributesComponent.h new file mode 100644 index 0000000..6200cf8 --- /dev/null +++ b/Source/Exo/Public/Characters/Components/ExoPlayerAttributesComponent.h @@ -0,0 +1,28 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Components/ActorComponent.h" +#include "ExoPlayerAttributesComponent.generated.h" + + +UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) +class EXO_API UExoPlayerAttributesComponent : public UActorComponent +{ + GENERATED_BODY() + +public: + // Sets default values for this component's properties + UExoPlayerAttributesComponent(); + +protected: + // Called when the game starts + virtual void BeginPlay() override; + +public: + // Called every frame + virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + + +}; diff --git a/Source/Exo/Public/Player/ExoPlayerController.h b/Source/Exo/Public/Player/ExoPlayerController.h index 65dc0ab..00cf92d 100644 --- a/Source/Exo/Public/Player/ExoPlayerController.h +++ b/Source/Exo/Public/Player/ExoPlayerController.h @@ -7,6 +7,7 @@ #include #include "ExoPlayerController.generated.h" +class AExoPlayerCharacter; class UInputMappingContext; class UInputAction; struct FInputActionValue; @@ -120,7 +121,7 @@ protected: TObjectPtr ChangeWeaponAction; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Character") - TObjectPtr PlayerCharacter; + TObjectPtr PlayerCharacter; private: UInteractionComponent* InteractionComponent;