I am using an AssetFactory to enable asset creation for a custom asset type via drag and drop in the editor. As the asset does contain some additional data, I want to create a subdirectory where I store that data in. To do so, I create another package with the path of the subdirectory:
// This comes from an AssetFactory
UObject* RootPackage = ...; // The directory where the asset was dragged into in the editor (UPackage)
FString FilePath = ...; // The path to the file that was dragged into the editor
// Extracting the directories and filename
FString Directory, FileName, PackagePath;
FImportUtils::SplitPath(RootPackage->GetFullName(), PackagePath, FileName);
FImportUtils::SplitPath(FilePath, Directory, FileName);
// First create the new directory - this does work just as expected
const FString NewPackagePath = FPaths::Combine(PackagePath, TEXT("MySubdirectory"));
// Chop these 14 characters: "Package /Game/"
const FString PackageAbsolutePath = FPaths::ConvertRelativePathToFull(FPaths::Combine(FPaths::ProjectContentDir(), NewPackagePath.RightChop(14)));
FImportUtils::VerifyOrCreateDirectory(PackageAbsolutePath);
// Now create a package for the new subdirectory (but is this even necessary?)
UPackage* NewPackage = CreatePackage(*NewPackagePath);
// Some code that creates an asset inside of the subdirectory (subpackage)
UObject* NewAsset = ...;
// Save the new asset (copied from this blogpost: https://isaratech.com/save-a-procedurally-generated-texture-as-a-new-asset/)
FString PackageFileName = FPackageName::LongPackageNameToFilename(
NewPackage->GetName(), FPackageName::GetAssetPackageExtension());
UPackage::Save(NewPackage, NewAsset, RF_Standalone | RF_Public, *PackageFileName);
When running this code, I get the following error for the LongPackageNameToFilename
command:
“Path does not map to any roots”
The path does exist, however, it was freshly created (successfully), so no I am wondering if it is even necessary to create a new package, or if I can create the assets in the original package with a different path. Unfortunately, I could not find any information at all what a “package” even is or what the difference between a package and an asset actually is.