Question on how to correctly save a map package in a custom commandlet

Hello, we have written a custom commandlet regenerates some actors and resaves the map. We’ve seen the error “AssetSaveMissingStandaloneFlag” while saving packages and were wondering what the correct way to save an .umap package without hitting this is. Here is our current code when saving the map:

  const FString PackageFileName = SourceControlHelpers::PackageFilename(MapPackage);
  FSavePackageArgs SaveArgs;
  SaveArgs.TopLevelFlags = RF_Standalone;
  SaveArgs.SaveFlags = SAVE_Async;
  if (!UPackage::SavePackage(MapPackage, nullptr, *PackageFileName, SaveArgs))
  {
    // ... handle error
    ...

We’re finding the issue a little hard to reproduce - I was able to hit it once, but it went away after -dpcvars=save.FixupStandaloneFlags=1 to the command line arguments and I’ve not been able to reproduce it since with or without that argument, so I’m not exactly sure what the precondition for triggering the error is.

I suspect that some of our flags are wrong but I’m having difficulty finding what the correct way of saving a map package updated via a custom commandlet is. Is there any documentation on this?

Steps to Reproduce

Hello!

The RF_StandAlone top level flag is required. I would recommend that your commandlet uses SavePackageHelper which is used by most commandlets in the engine. This method will me more robust than directly calling UPackage::SavePackage as it is meant to be used as a lighter reference API at the editor level.

Regards,

Martin