【发布时间】: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