【问题标题】:Pointer to incomplete class type is not allowed Unreal Engine 4.26不允许指向不完整类类型的指针 Unreal Engine 4.26
【发布时间】:2021-02-20 19:53:26
【问题描述】:

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

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;

};

【问题讨论】:

  • 请完整发布错误。
  • 我添加了完整的错误列表:)

标签: c++ unreal-engine4


【解决方案1】:

您可能还需要将NavigationSystem 模块添加到PublicDependencyModuleNames 数组中的Project.Build.cs 文件中。

【讨论】:

  • 感谢您绕过 LNK2019。
【解决方案2】:

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

【讨论】:

  • 在 UE 4.20 及更高版本的 UNNavigationPath 中,它包含在我包含的 NavigationSystem.h 中。 #include "Runtime/NavigationSystem/Public/NavigationSystem.h"
  • 奇怪的是,源代码中的 #include 行使用反斜杠而不是正斜杠。这对您的系统有效吗?
  • 第一次是这样自动生成的,后来改成正斜杠样式,好像双向都可以。
  • @RobertMaximus 尝试直接包含相关标头:/Engine/Source/Runtime/NavigationSystem/Public/NavigationPath.h
  • 我认为您的包含或包含路径有些问题。您正在执行#include "Components/StaticMeshComponent.h",然后您将InputComponent.h 包含在不同的路径中,即使这些标头位于同一目录中。您确定您的构建没有发出关于无法找到头文件的警告,或者可能通过不同的路径包含相同的头文件?
猜你喜欢
  • 2021-12-31
  • 2012-08-15
  • 2015-10-09
  • 2017-10-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多