Help with modifying the ResavePackage commandlet to automate landscape rebuilding on maps

Hello, I am currently trying to modify the ResavePackages commandlet to support rebuilding the landscapes for nanite, physical materials, etc.

I am doing this in UResavePackagesCommandlet::PerformAdditionalOperations function of the ContentCommandlet.cpp file.

In that function I added code so that if the user specifies a -BuildLandscape switch, it will call:

  • LandscapeSubsystem::BuildAll()

then the rest of the funcion runs normally, and eventually, the rest of the vanilla commandlet code will save the package.

Things seem to work. I get all the same rebuild log messages in the output as when rebuilding a landscape from the editor.

However after I open the map in the editor, I still keep getting the warning about Landscape actor being outdated and that it needs to be rebuilt. I even passed -AllowCommandletRendering incase the process required GPU access, but got the same result.

This doesn’t happen if I rebuild the landscape from the editor, and as far as I could tell, it calls the same functions essentially.

Do you know what am I missing here?

Thanks!

`if (bBuildLandscapes)
{
ULandscapeSubsystem* LandscapeSubsystemPtr = World->GetSubsystem();

if (IsValid(LandscapeSubsystemPtr))
{
TArray<TTuple<ALandscapeProxy*, UE::Landscape::EOutdatedDataFlags>> ProxyDetails =
LandscapeSubsystemPtr->GetOutdatedProxyDetails(UE::Landscape::EOutdatedDataFlags::All, false);

bShouldProceedWithRebuild = bShouldBuildNavigationData;
for (auto Proxy : ProxyDetails)
{
ULevel* OuterLevel = Cast(Proxy.Key->GetLandscapeActor()->GetOuter());
if (OuterLevel && OuterLevel->IsPersistentLevel())
{
FString MapPackageName;
if (!FPackageName::DoesPackageExist(World->GetPackage()->GetName(), &MapPackageName))
{
continue;
}

// Maybe not needed, but checked out here just in case
// that was the issue. Checking out does work
if (!CheckoutFile(MapPackageName))
{
continue;
}

LandscapeSubsystemPtr->BuildAll();

bShouldProceedWithRebuild = true;
break;
}
}
}
else if (!bShouldBuildNavigationData)
{
bShouldProceedWithRebuild = false;
}
}`

Turns out that sometimes, such as when upgrading maps from one version of the engine (5.3.2) to another (5.5.4), the re-saving happens in steps. After you rebuild the landscape the first time, the GUIDs of the proxy vs the nanite components will be recalculated and saved, however that sometimes causes that upon reloading, the GUID of the proxy changes once again, leaving the nanite component GUIDs outdated again, so I had to do rebuild in a loop, saving the level, doing a garbage collection and reloading it again to verify that there are no more outdated proxies, until there aren’t. This fixed my problem.

Hope it helps someone!

Hello,

I apologize for the delay. Nothing is really standing out to me. Did you confirm the list of packages resaved from the commandlet are the same as when ran from the editor? Could you share the exact message as well?

Thanks,

Ryan