PlayerController вызывает краш

Вот PlayerController.cpp:

#include "PawnPlayerController.h"
#include "../Public/MainPawn.h"
#include "Components/InputComponent.h"
#include "Kismet/GameplayStatics.h"

DEFINE_LOG_CATEGORY_STATIC(LogChangePawn, All, All);

void APawnPlayerController::BeginPlay()
{

    UGameplayStatics::GetAllActorsOfClass(GetWorld(), AMainPawn::StaticClass(), Pawns);
}

void APawnPlayerController::SetupInputComponent()
{
    InputComponent->BindAction(FName("ChangePawn"), IE_Pressed, this, &APawnPlayerController::ChangePawn);
}

void APawnPlayerController::ChangePawn()
{
    UE_LOG(LogChangePawn, Error, TEXT("Change Pawn called"));
    if (Pawns.Num() <= 1)
        return;
    CurrentPawn = Cast<AMainPawn>(Pawns[IdPawn]);
    IdPawn = (IdPawn + 1) % Pawns.Num();
    if (!CurrentPawn)
        return;
    Possess(CurrentPawn);
}

Вот PlayerController.h:

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "PawnPlayerController.generated.h"

class AMainPawn;

/**
 *
 */
UCLASS()
class MOVABLECHARACTER_API APawnPlayerController : public APlayerController
{
    GENERATED_BODY()
    UPROPERTY()
    TArray<AActor *> Pawns;

  protected:
    virtual void SetupInputComponent() override;
    virtual void BeginPlay() override;
    int32 IdPawn = 1;
    AMainPawn *CurrentPawn;
    void ChangePawn();
};

Ответы (0 шт):