fix: correct player character check

add player attribute component test class
This commit is contained in:
Foxim 2025-02-21 15:59:46 +01:00
parent d95a23f2e7
commit 40e5a37d91
4 changed files with 69 additions and 4 deletions

View File

@ -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);
// ...
}

View File

@ -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<AExoPlayerCharacter>(GetPawn<ACharacter>());
check(PlayerCharacter);
UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer());
if (Subsystem)
{
Subsystem->AddMappingContext(InputContext, 0);
}
PlayerCharacter = GetPawn<ACharacter>();
InteractionComponent = PlayerCharacter->FindComponentByClass<UInteractionComponent>();
}

View File

@ -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;
};

View File

@ -7,6 +7,7 @@
#include <Player/InteractionComponent.h>
#include "ExoPlayerController.generated.h"
class AExoPlayerCharacter;
class UInputMappingContext;
class UInputAction;
struct FInputActionValue;
@ -120,7 +121,7 @@ protected:
TObjectPtr<UInputAction> ChangeWeaponAction;
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Character")
TObjectPtr<ACharacter> PlayerCharacter;
TObjectPtr<AExoPlayerCharacter> PlayerCharacter;
private:
UInteractionComponent* InteractionComponent;