[UE5.3]How to create a NavMesh in memory only without being garbage collected?

I want to create an AStar NavMesh in memory only. All the data is in memory and getting a path works fine. It seems I have to use SpawnActor() to create it but it ends up being garbage collected right away.

I’ve added it the list of Supported Agents. I’ve registered it. I’ve set the owner to an actor in the level and assigned it to a TObjectPtr property. It still gets destroyed automatically. The InitialLifeSpan is zero so should be infinite.

Any idea why it gets garbage collected right away?

It’s saying that registration failed. That seems to be why it’s being despawned. It says the navmesh doesn’t support any of the expected agent types. I’m seeing there’s a FNavDataConfig. Maybe I have to set that, but I have no idea how to load that from the project settings at runtime.

Ok, I learned a few things. I don’t need to register the navmesh. Registering is the same thing as adding it in the Supported Agents list in the Project Settings.

Also, I don’t have to spawn it at all. You just grab the NavigationSystem and do a query on it using one of the agents which will grab one of the navmeshes already built for you.

This is how I did it.

    FPathFindingQuery Query;
    Query.StartLocation = StartTile->Position;
    Query.EndLocation = EndTile->Position;
    FSharedNavQueryFilter QueryFilter = MakeShareable(new FNavigationQueryFilter());
    Query.QueryFilter = QueryFilter;

    UNavigationSystemV1* NavSys = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld());
    check(NavSys);
    FNavDataConfig config = NavSys->GetSupportedAgents()[2];
    
    FPathFindingResult Result = NavSys->FindPathSync(config, Query);

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.