Implementing Custom Pathfinding: Bugs and Crashes

Hello there,
for my project, I wanted to implement a custom Pathfinding that works without a nav mesh. The idea was, that I was making a solar system with space ships navigating in 3D. It is an RTS, the idea was to implement an algorithm, that draws a direct path from A to B and using avoidance in his close proximity for anything on it’s way (maybe even through detour, haven’t tested it yet). I thought this might be a good idea, as nearly anything will be somehow moving (even the planets), therefore I won’t have static obstacles, and the ships can directly fly around everything (they can’t get stuck in holes or similar). I have some coding experiene, but not much and am fairly new to c++.

Now to my actual problem: I was already able to implement my own pathfinding system through extending the ANavigationData class. I was basically following this tutorial, with the exeption of extending ANavigationData instead of ARecastNavMesh (as I don’t want nav mesh, as explained). Have a look at the link under “Hooking Our RecastNavMesh Into The Engine” if you want to see how I hooked it up with my project.
So far, my code works and I have no compiler errors, the path is simply one between the pawn position and a goal position. But I have to fight with some odd behaviour.

  1. My custom pathfinding class (called AShipNavigation) does only do things (printing out logs) when I add a Nav Mesh Bounds Volume to the scene. The pawn does still not move, and when I try to observe it with the visual logger, the engine simply crashes. In the Log, I cannot find any messages or that the engine writes that it is terminating by purpose. Have a look at the Crash Log, the Warnings at the buttom are Logs written by me (proving that my own NavigationData class is hooked up and runs). When running it through the VS Windows Debugger, I get an exception that my NavMesh was nullptr.

  2. When running the map without the nav mesh bounds volume, nothing happens. My pathfinder doesn’t fire, the move functions return failure instead success. Observing it with the visual logger, I receive the message: “LogAINavigation (Warning) Unable to find NavigationData instance while calling AAIController::BuildPathfindingQuery”

My conclusion: When adding the nav mesh bounds, somehow an (invisible?) NavigationData instance is generated. When adding the nav mesh bounds, one is generated for recast nav mesh, which doesn’t match my pathfinding. In the tutorial it works of cause, as the A* pathfinding is derived from the recast nav mesh. When I therefore want to run my pathfinding, I have to add something, probably the NavigationData instance the visual logger is missing in case 2. But how? And where?

In general, this whole thing is a big pain in the ■■■, as there are a lot of classes, like Navigation System oder NavigationData, that are nowhere explained, not even the code has a comment at the start of each headerfile to explain what the classes’ purpose is. This is a bit tiring… the documentation is basicly just a collection of all functions, doesn’t tell more then the code already does.

Thanks if you read so far, I hope someone knows the navigation system better then me and knows what I am missing.

1 Like

Ok, here is the solution, in case anyone comes across this very same issue:

  1. I had to activate my own ShipNavigation Navigation Data as the “Preferred Nav Data” in the pawns movement component.
  2. I created a scene manager class that is in every one of my scenes. Over there. I implemented the following code into the beginPlay method:

.h:


	UNavigationSystemV1* CurrentNavSys;
	AShipNavigation* ShipNavigationInstance;
	const FNavDataConfig* NavigationDataConfig;

.cpp:



	CurrentNavSys = FNavigationSystem::GetCurrent(GetWorld());
	check(CurrentNavSys);
	NavigationDataConfig = &CurrentNavSys->GetDefaultSupportedAgent();

	if (CurrentNavSys)
	{
		if (!ShipNavigationInstance)
		{
			ShipNavigationInstance = AShipNavigation::SpawnInstance(CurrentNavSys, NavigationDataConfig);
		}
		else
		{
			UE_VLOG(this, LogNavigation, Warning, TEXT("ASolarSystemManager::ASolarSystemManager ShipNavigationInstance already set"));
		}
	}
	else
	{
		UE_VLOG(this, LogNavigation, Warning, TEXT("ASolarSystemManager::ASolarSystemManager couldn't find a Navigation System"));
	}

Important note: check the code yourself, I am currently getting crashes sometimes when using the visual logger, but the code compiles without errors.

Basicly, I am creating and the level begin my custom navigation data as an instance.