Last active
October 29, 2023 20:11
-
-
Save dacanizares/5db9c59281a9c9049bf819acce7e29bc to your computer and use it in GitHub Desktop.
Sample AI Controller - GetRandomReachablePointInRadius - UE4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Test/MovementAIController.h" | |
#include "Runtime/Engine/Classes/Kismet/GameplayStatics.h" | |
#include "AI/NavigationSystemBase.h" | |
#include "NavigationSystem.h" | |
void AMovementAIController::BeginPlay() | |
{ | |
Super::BeginPlay(); | |
GoToRandomWaypoint(); | |
} | |
void AMovementAIController::GoToRandomWaypoint() | |
{ | |
FVector Result; | |
if (GetRandomPointInRadius(GetPawn()->GetActorLocation(), 600, Result)) { | |
MoveToLocation(Result); | |
} | |
} | |
bool AMovementAIController::GetRandomPointInRadius(const FVector& Origin, float Radius, FVector& OutResult) | |
{ | |
UNavigationSystemV1* NavSys = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld()); | |
if (!NavSys) | |
{ | |
return false; | |
} | |
FVector Result; | |
bool bSuccess = NavSys->K2_GetRandomReachablePointInRadius(GetWorld(), Origin, Result, 600); | |
//Out | |
OutResult = Result; | |
return bSuccess; | |
} | |
void AMovementAIController::OnMoveCompleted(FAIRequestID RequestID, const FPathFollowingResult& Result) | |
{ | |
Super::OnMoveCompleted(RequestID, Result); | |
GoToRandomWaypoint(); | |
} |
Probably you need to add some modules to the PublicDependencyModuleNames of your ProjectName.Build.cs file:
using System.IO;
using UnrealBuildTool;
public class ProjectName: ModuleRules
{
public ProjectName(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
"CoreUObject",
"Engine",
"InputCore",
"PhysicsCore",
"AIModule", // ADD
"NavigationSystem", // ADD
}
);
....
}
}
Usually LNK errors are related with that kind of issues.
thanks Dacanizares
…On Sun, 15 May 2022 at 11:44, Daniel Cañizares Corrales < ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Probably you're missing to add some modules to the
PublicDependencyModuleNames of your ProjectName.Build.cs file:
using System.IO;
using UnrealBuildTool;
public class ProjectName: ModuleRules
{
public ProjectName(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
"CoreUObject",
"Engine",
"InputCore",
"PhysicsCore",
"DeveloperSettings",
"Paper2D",
"AIModule", // ADD
"NavigationSystem", // ADD
}
);
....
}
}
Usually LNK errors are related with that kind of issues.
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/5db9c59281a9c9049bf819acce7e29bc#gistcomment-4167393>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ATWVK4BYCVX6RVMYTZGE4I3VKCI57ANCNFSM5SLJP5GA>
.
You are receiving this because you commented.Message ID:
***@***.***>
No problem!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey I am trying to use and getting this error
CompilerResultsLog: Error: EnemyAIController.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static bool __cdecl UNavigationSystemV1::K2_GetRandomReachablePointInRadius(class UObject *,struct FVector const &,struct FVector &,float,class ANavigationData *,class TSubclassOf)" (_imp?K2_GetRand
omReachablePointInRadius@UNavigationSystemV1@@SA_NPEAVUObject@@AEBUFVector@@AEAU3@MPEAVANavigationData@@v?$TSubclassOf@VUNavigationQueryFilter@@@@@z) referenced in function "public: bool __cdecl AEnemyAIController::GetRandomPointInRadius(struct FVector const &,float,struct FVector &)" (?GetRandomPointInRadius@AEnemyAIController@@QEAA_NAEBUFVector@@MAEAU2@@z)
CompilerResultsLog: Error: D:\Prabh\unreal\Devlopment\CoolTanks\Binaries\Win64\UE4Editor-CoolTanks-7059.dll : fatal error LNK1120: 2 unresolved externals