| 46 | namespace URLabLevelOps |
| 47 | { |
| 48 | bool ImportXmlSync( |
| 49 | const FString& AbsXmlPath, |
| 50 | bool bForceReimport, |
| 51 | FString& OutBlueprintClassPath, |
| 52 | FString& OutBlueprintShortName, |
| 53 | bool& bOutImportedNow, |
| 54 | FString& OutError) |
| 55 | { |
| 56 | OutBlueprintClassPath.Empty(); |
| 57 | OutBlueprintShortName.Empty(); |
| 58 | bOutImportedNow = false; |
| 59 | OutError.Empty(); |
| 60 | |
| 61 | if (!FPaths::FileExists(AbsXmlPath)) |
| 62 | { |
| 63 | OutError = FString::Printf(TEXT("xml file not found: %s"), *AbsXmlPath); |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | const FString StemBase = FPaths::GetBaseFilename(AbsXmlPath); |
| 68 | const FString DestPath = TEXT("/Game/MuJoCoImports"); |
| 69 | const FString ObjectPath = FString::Printf(TEXT("%s/%s.%s"), *DestPath, *StemBase, *StemBase); |
| 70 | const FString GeneratedClassPath = FString::Printf( |
| 71 | TEXT("%s/%s.%s_C"), *DestPath, *StemBase, *StemBase); |
| 72 | |
| 73 | // Reuse path: asset already exists and caller didn't force a reimport. |
| 74 | FAssetRegistryModule& AssetRegistry = |
| 75 | FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry")); |
| 76 | FAssetData Existing = AssetRegistry.Get().GetAssetByObjectPath(FSoftObjectPath(ObjectPath)); |
| 77 | if (!bForceReimport && Existing.IsValid()) |
| 78 | { |
| 79 | OutBlueprintClassPath = GeneratedClassPath; |
| 80 | OutBlueprintShortName = StemBase; |
| 81 | bOutImportedNow = false; |
| 82 | return true; |
| 83 | } |
| 84 | |
| 85 | // Force-reimport path: ImportAssetsAutomated(bReplaceExisting=true) |
| 86 | // does NOT delete the in-memory UBlueprint before our factory's |
| 87 | // FKismetEditorUtilities::CreateBlueprint runs. CreateBlueprint |
| 88 | // asserts on FindObject<UBlueprint>(...) == 0 -> editor crash. |
| 89 | // Destroy the existing asset ourselves first. |
| 90 | if (bForceReimport && Existing.IsValid()) |
| 91 | { |
| 92 | bool bWasFound = false; |
| 93 | FString DestroyErr; |
| 94 | if (!DestroyAssetSync(ObjectPath, bWasFound, DestroyErr)) |
| 95 | { |
| 96 | OutError = FString::Printf( |
| 97 | TEXT("force_reimport failed to clear existing BP %s: %s"), |
| 98 | *ObjectPath, *DestroyErr); |
| 99 | return false; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | // Drive the existing factory programmatically. |
| 104 | FAssetToolsModule& AssetToolsModule = |
| 105 | FModuleManager::LoadModuleChecked<FAssetToolsModule>(TEXT("AssetTools")); |