不允许指向不完整类类型的指针 Unreal Engine 4.26

时间:2021-02-20 19:53:26

标签: c++ unreal-engine4

我尝试在我的游戏中为玩家实现 pawn 导航。当我在 BP 网站上尝试时,它运行得很好,但我尝试在 C++ 代码中转换它。我有一种奇怪的错误。在此之前,我遇到了另一个错误,但我发现我的 ue 版本中的 NavigationSystem 发生了一些变化,但是我通过更改为 UNavigationSystemV1 解决了问题。它可能会干扰我的课程?

NavPath 指针它给了我错误。

这是错误列表:

> Error (active)    E0393   pointer to incomplete class type is not allowed 37
> Error (active)    E0393   pointer to incomplete class type is not allowed 40
> Error C2027   use of undefined type 'UNavigationPath'37
> Error C2027   use of undefined type 'UNavigationPath' 40

这是有问题的代码部分:

FVector ASTrackerBot::GetNextPathPoint()
{
ACharacter* PlayerPawn =  UGameplayStatics::GetPlayerCharacter(this, 0);

UNavigationPath* NavPath = UNavigationSystemV1::FindPathToActorSynchronously(this, 
GetActorLocation(), PlayerPawn);

if (NavPath->PathPoints.Num() > 1)
{

    return NavPath->PathPoints[1];
}


return GetActorLocation();

}

这是我的整个私人 cpp 文件:

#include "AI/STrackerBot.h"
#include "Components/StaticMeshComponent.h"
#include "GameFramework/Character.h"
#include "Kismet/GameplayStatics.h"
#include "Runtime\NavigationSystem\Public\NavigationSystem.h"
#include "Runtime/Engine/Classes/Components/InputComponent.h"


// Sets default values
ASTrackerBot::ASTrackerBot()
{
    // Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
    PrimaryActorTick.bCanEverTick = true;

    MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComp"));
    MeshComp->SetCanEverAffectNavigation(false);
    RootComponent = MeshComp;
}

// Called when the game starts or when spawned
void ASTrackerBot::BeginPlay()
{
    Super::BeginPlay();
    
}

FVector ASTrackerBot::GetNextPathPoint()
{
    // parcurgere drum pana la locatia playerului
    ACharacter* PlayerPawn =  UGameplayStatics::GetPlayerCharacter(this, 0);
    
    UNavigationPath* NavPath = UNavigationSystemV1::FindPathToActorSynchronously(this, GetActorLocation(), PlayerPawn);

    if (NavPath->PathPoints.Num() > 1)
    {
        // Return next point in the path
        return NavPath->PathPoints[1];
    }

    // nu a reusti sa gaseasca drumul
    return GetActorLocation();
}

// Called every frame
void ASTrackerBot::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

}

这是我的头文件:

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "STrackerBot.generated.h"

UCLASS()
class GAME_API ASTrackerBot : public APawn
{
    GENERATED_BODY()

public:
    // Sets default values for this pawn's properties
    ASTrackerBot();

protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;

    UPROPERTY(VisibleAnywhere, Category = "Components")
    UStaticMeshComponent* MeshComp;

    FVector GetNextPathPoint();

public: 
    // Called every frame
    virtual void Tick(float DeltaTime) override;

};

2 个答案:

答案 0 :(得分:1)

UNavigationPath 的定义需要在您执行 NavPath->PathPoints 时可用。如果没有定义,编译器怎么知道 UNavigationPath 甚至有一个名为 PathPoints 的成员?您可以拥有一个指向已声明但未定义的类(即,您像 class UNavigationPath; 一样定义而没有主体的类)的指针并将其传递,但​​您无法访问其任何成员。找到定义 UNavigationPath 的头文件并确保它包含在您的源代码中。

答案 1 :(得分:1)

您可能还需要将 import type { Dispatch } from 'umi'; import ProForm, { ProFormText } from '@ant-design/pro-form'; import { message } from 'antd'; const tip = (type: string, content: string) => { if (type === 'error') message.error(content, 5); else message.success(content, 5); }; const RegisterFC: React.FC<RegisterProps> = (props) => { const { registerResponseInfo = {}, submitting, dispatch } = props; const { status } = registerResponseInfo; const handleSubmit = (values: RegisterParamsType) => { dispatch({ type: 'register/register', payload: { ...values }, }); }; return ( <div> <ProForm onFinish={(values) => { handleSubmit(values as RegisterParamsType); return Promise.resolve(); }} > <ProFormText/> ... { status === '1' && !submitting && ( tip('error', intl.formatMessage({ id: 'pages.register.status1.message', defaultMessage: 'error' }) ) ) } <<ProForm>/> </div> ) } const p = ({ register, loading }: { register: RegisterResponseInfo, loading: Loading; }) => { console.log(loading); return { registerResponseInfo: register, submitting: loading.effects['register/register'], }; }; export default connect(p)(RegisterFC); 模块添加到 NavigationSystem 数组中的 Project.Build.cs 文件中。