GetRandomPoint...InRadius works everywhere but in the packaged game.... how can I solve this?

Hallo! I’m in mystery land and hope somebody could shed light on what’s happening.

I have a custom Behavior Tree Task (code below) that I use to find a “random reachable point in radius”. The result is then fed to a standard MoveTo task. Everything works beautifully in PIE and even when I launch my maps as “Standalone Game”. However, if I package the game,

NavSys->GetRandomReachablePointInRadius(Origin, Radius, Result, navData);

fails (I know that’s the line that fails as I’ve debugged the heck out it). And I have no idea why. Here’s the code for the whole task:

EBTNodeResult::Type UBTTaskNode_FindRandomLocation::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	//Get Blackboard Component
	UBlackboardComponent* BlackboardComp = OwnerComp.GetBlackboardComponent();

	//Get Controlled Pawn
	APawn* ControlledPawn = OwnerComp.GetAIOwner()->GetPawn();

	//Get Navigation System
	UNavigationSystemV1* NavSys = UNavigationSystemV1::GetCurrent(GetWorld());

	//Get navData
	class ANavigationData* navData = NavSys->GetNavDataForAgentName(NavDataAgent);

	//Prepare variables for query
	FNavLocation Result;
	FVector Origin = ControlledPawn->GetActorLocation();
	float Radius = BlackboardComp->GetValueAsFloat(MaxRoamingDistance.SelectedKeyName);
	
	//Perform Query
	bool bSuccess = NavSys->GetRandomReachablePointInRadius(Origin, Radius, Result, navData);

	//Save result and return success	
	BlackboardComp->SetValueAsVector(DestinationVector.SelectedKeyName, Result.Location);
	return EBTNodeResult::Succeeded;
}

Any help, even just to address me towards how to find what’s going wrong, it’s super appreciated.

Thank you in advance,

f

A couple more info, in case they might be useful:

  • This happens in either a Shipping or a DebugGame build
  • I’ve tried to delete all the cached data (these folders: DerivedDataCache, Intermediate, Build, Binaries)… problem persists

Keeping on fiddling and searching, and I’ve found a post from 2017 reporting a similar problem. Following @rogeriooo lead, I’ve tried to switch my Radius value, as it was fetched from the blackboard:

float Radius = BlackboardComp->GetValueAsFloat(MaxRoamingDistance.SelectedKeyName);

…with a fixed value, and et woila’, everything works:
bool bSuccess = NavSys->GetRandomReachablePointInRadius(Origin, Radius, 2500.f, navData);

Presently I don’t know yet if the issue is with retrieving the value, or with setting it. Hopefully I’ll figure that out. Stay tuned.

Cheers

f

…aaaaand eventually I managed to get to the root of the problem and solve it. The actual problem: in the packaged game the Blackboard key MaxRoamingDistance was not being set.

In the game I’m making that’s a variable that’s dependent on the level you’re currently in. So it made sense to me to have that variable belong to the LevelScriptActor and have the LevelScriptActor itself write it to that Blackboard. However! Looks like in a packaged game that Blackboard doesn’t exist yet when my LevelScriptActor tries to write to it. And it makes sense: first the LevelScriptActor is spawned; then the character running the Behavior Tree we’re considering; and I believe the Blackboard starts existing in memory only after that character has been possessed by the AI controller that actually ends up running the Behavior Tree.

The solution was to have that Blackboard value written by the AI controller once the character was possessed – pulling it from the LevelScriptActor rather than vice-versa.

And generally speaking, that’s always a good principle when programming in Unreal C++: when it comes to data, always pull, never push!

Cheers

f