C++ 不允许指向不完整类类型的指针不真实引擎4.26
我尝试在我的游戏中为玩家实现典当导航。当我在BP站点尝试过时,它的工作非常完美,但是我尝试用C++代码来转换它。我犯了一种错误。在此之前,我遇到了另一个错误,但我发现导航系统在我的ue版本中有点改变,但我通过更改为UNavigationSystemV1解决了问题。这可能会干扰我的课堂 导航路径指针它给了我错误 以下是错误列表:C++ 不允许指向不完整类类型的指针不真实引擎4.26,c++,unreal-engine4,C++,Unreal Engine4,我尝试在我的游戏中为玩家实现典当导航。当我在BP站点尝试过时,它的工作非常完美,但是我尝试用C++代码来转换它。我犯了一种错误。在此之前,我遇到了另一个错误,但我发现导航系统在我的ue版本中有点改变,但我通过更改为UNavigationSystemV1解决了问题。这可能会干扰我的课堂 导航路径指针它给了我错误 以下是错误列表: > Error (active) E0393 pointer to incomplete class type is not allowed 37 >
> 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);
}
unvigationpath
的定义需要在执行NavPath->PathPoints
的位置可用。如果没有定义,编译器如何知道unvigationpath
甚至有一个名为PathPoints
的成员?您可以有一个指向已声明但未定义的类的指针(即,您定义的类,如类unvigationpath;
没有正文),并将其传递给其他人,但不能访问其任何成员。查找定义unvigationpath
的头文件,并确保它包含在源代码中。需要在执行NavPath->PathPoints
的位置提供unvigationpath
的定义。如果没有定义,编译器如何知道unvigationpath
甚至有一个名为PathPoints
的成员?您可以有一个指向已声明但未定义的类的指针(即,您定义的类,如类unvigationpath;
没有正文),并将其传递给其他人,但不能访问其任何成员。查找定义unvigationpath
的头文件,并确保它包含在源代码中。您可能还需要将导航系统
模块添加到PublicDependencyModuleNames
数组中的Project.Build.cs文件中。您可能还需要将导航系统
模块添加到源代码中PublicDependencyModuleNames
数组中的Project.Build.cs文件。请完整发布错误。我添加了完整的错误列表:)请完整发布错误。我添加了完整的错误列表:)在UE 4.20中以及在导航系统.h中包含的不可用路径之上,我包括了导航系统#包含“Runtime/NavigationSystem/Public/NavigationSystem.h”,奇怪的是,源代码中的include行使用反斜杠而不是正斜杠。这在您的系统上有效吗?第一次是这样自动生成的,然后我改为正斜杠样式,它似乎在两种方式下都有效。@RobertMaximus尝试直接包含相关标题:/Engine/Source/Runtime/NavigationSystem/Public/NavigationPath。我认为您的包含或包含路径有问题。您正在执行#包含“Components/StaticMeshComponent.h”
,然后使用不同的路径包含InputComponent.h
,即使这些头位于同一目录中。你确定你的构建没有发出关于无法找到头文件的警告,或者可能通过不同的路径包含相同的头文件吗?在UE 4.20和以上版本的UNavigationPath中,它包含在NavigationSystem.h中,我包括了它#包含“Runtime/NavigationSystem/Public/NavigationSystem.h”,奇怪的是,源代码中的include行使用反斜杠而不是正斜杠。这在您的系统上有效吗?第一次是这样自动生成的,然后我改为正斜杠样式,它似乎在两种方式下都有效。@RobertMaximus尝试直接包含相关标题:/Engine/Source/Runtime/NavigationSystem/Public/NavigationPath。我认为您的包含或包含路径有问题。您正在执行#包含“Components/StaticMeshComponent.h”
,然后使用不同的路径包含InputComponent.h
,即使这些头位于同一目录中。你确定你的构建没有发出关于无法找到头文件的警告,或者可能通过不同路径包含相同的头文件吗?感谢绕过LNK2019成功。感谢绕过LNK2019成功。
#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;
};