fix: initialize components in constructor to prevent crash

This commit is contained in:
Foxim 2025-03-07 11:11:22 +01:00
parent 1b93280fa7
commit c9a138e1ab
4 changed files with 18 additions and 2 deletions

View File

@ -2,12 +2,19 @@
#include "Characters/ExoPlayerCharacter.h" #include "Characters/ExoPlayerCharacter.h"
#include "Characters/Components/ShootingComponent.h"
#include "GameFramework/CharacterMovementComponent.h" #include "GameFramework/CharacterMovementComponent.h"
#include "Player/InteractionComponent.h"
AExoPlayerCharacter::AExoPlayerCharacter() AExoPlayerCharacter::AExoPlayerCharacter()
{ {
GetCharacterMovement()->bSnapToPlaneAtStart = true; GetCharacterMovement()->bSnapToPlaneAtStart = true;
InteractionComponent = CreateDefaultSubobject<UInteractionComponent>(TEXT("Interaction Component"));
ShootingComponent = CreateDefaultSubobject<UShootingComponent>(TEXT("Shooting Component"));
bUseControllerRotationPitch = true; bUseControllerRotationPitch = true;
bUseControllerRotationYaw = true; bUseControllerRotationYaw = true;
bUseControllerRotationRoll = false; bUseControllerRotationRoll = false;
@ -16,5 +23,5 @@ AExoPlayerCharacter::AExoPlayerCharacter()
void AExoPlayerCharacter::BeginPlay() void AExoPlayerCharacter::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
check(InteractionComponent && ShootingComponent);
} }

View File

@ -31,7 +31,7 @@ void AExoPlayerController::BeginPlay()
InteractionComponent = PlayerCharacter->FindComponentByClass<UInteractionComponent>(); InteractionComponent = PlayerCharacter->FindComponentByClass<UInteractionComponent>();
ShootingComponent = PlayerCharacter->FindComponentByClass<UShootingComponent>(); ShootingComponent = PlayerCharacter->FindComponentByClass<UShootingComponent>();
// Ustawianie w komponencie poruszania prędkości zapisanej w characterze // Ustawianie w komponencie poruszania pr<EFBFBD>dko<EFBFBD>ci zapisanej w characterze
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->WalkSpeed; PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->WalkSpeed;
} }

View File

@ -6,6 +6,9 @@
#include "Characters/ExoCharacterBase.h" #include "Characters/ExoCharacterBase.h"
#include "ExoPlayerCharacter.generated.h" #include "ExoPlayerCharacter.generated.h"
class UInteractionComponent;
class UShootingComponent;
UCLASS() UCLASS()
class EXO_API AExoPlayerCharacter : public AExoCharacterBase class EXO_API AExoPlayerCharacter : public AExoCharacterBase
{ {
@ -14,6 +17,12 @@ class EXO_API AExoPlayerCharacter : public AExoCharacterBase
public: public:
AExoPlayerCharacter(); AExoPlayerCharacter();
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
TObjectPtr<UInteractionComponent> InteractionComponent;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
TObjectPtr<UShootingComponent> ShootingComponent;
UPROPERTY(EditAnywhere, Category = "Dodge Properties") UPROPERTY(EditAnywhere, Category = "Dodge Properties")
float DodgeForce = 5000.f; float DodgeForce = 5000.f;