Reputation:
I try to implement the pawn navigation to the player in my game. When I tried that in BP site, it worked perfectly, but I try to transform that in C++ code. And I got a kind of wird error. Befor this I faced another error but I find the NavigationSystem was changed a bit in my ue version, but I figured out problem by changing to UNavigationSystemV1. It might be interfering with my class?
NavPath pointer it gave me the error.
Here is the error list:
> 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
Here is the part of problematic code:
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();
}
Here is my entire private cpp file:
#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);
}
And here is my header file:
#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;
};
Upvotes: 0
Views: 1184
Reputation: 597
You may also need to add the NavigationSystem
module to your Project.Build.cs file in the PublicDependencyModuleNames
array.
Upvotes: 0
Reputation: 8204
The definition of UNavigationPath
needs to be available at the point where you do NavPath->PathPoints
. Without the definition, how does the compiler know that UNavigationPath
even has a member called PathPoints
? You can have a pointer to a declared but undefined class (i.e., one you defined like class UNavigationPath;
with no body) and pass it around but you can't access any of its members. Find the header file that defines UNavigationPath
and make sure it's included in your source.
Upvotes: 1