MCPcopy Create free account
hub / github.com/URLab-Sim/UnrealRoboticsLab / DestroyAssetSync

Function DestroyAssetSync

Source/URLabEditor/Private/MjLevelOps.cpp:219–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

217}
218
219bool DestroyAssetSync(const FString& ObjectPath, bool& bOutWasFound, FString& OutError)
220{
221 bOutWasFound = false;
222 OutError.Empty();
223
224 FAssetRegistryModule& AR = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry"));
225 FAssetData Existing = AR.Get().GetAssetByObjectPath(FSoftObjectPath(ObjectPath));
226 if (!Existing.IsValid())
227 {
228 UE_LOG(LogURLabEditor, Log,
229 TEXT("DestroyAsset: no asset at %s (idempotent no-op)"), *ObjectPath);
230 return true;
231 }
232 bOutWasFound = true;
233
234 // If a UWorld currently loaded, switch off it first so its
235 // package can be deleted.
236 UWorld* CurWorld = GEditor ? GEditor->GetEditorWorldContext().World() : nullptr;
237 if (CurWorld && CurWorld->GetOutermost() == Existing.GetPackage())
238 {
239 ULevelEditorSubsystem* Sub = GetLevelSub();
240 if (Sub)
241 Sub->LoadLevel(TEXT("/Engine/Maps/Templates/Template_Default"));
242 }
243
244 UObject* AssetObj = Existing.GetAsset();
245 if (!AssetObj)
246 {
247 OutError = FString::Printf(
248 TEXT("AssetData.GetAsset() returned null for %s"), *ObjectPath);
249 return false;
250 }
251 const FString PathBeforeDelete = AssetObj->GetPathName();
252 TArray<UObject*> ToDelete = {AssetObj};
253 const int32 NumDeleted = ObjectTools::ForceDeleteObjects(ToDelete, /*bShowConfirmation*/ false);
254 UE_LOG(LogURLabEditor, Log,
255 TEXT("DestroyAsset: ForceDeleteObjects returned %d for %s"),
256 NumDeleted, *PathBeforeDelete);
257 if (NumDeleted == 0)
258 {
259 OutError = FString::Printf(
260 TEXT("ForceDeleteObjects refused %s (live references?)"),
261 *PathBeforeDelete);
262 return false;
263 }
264 return true;
265}
266
267bool LoadLevelSync(const FString& NameOrPath, FString& OutLevelPath, FString& OutError)
268{

Callers 3

ImportXmlSyncFunction · 0.85
CreateLevelSyncFunction · 0.85
HandleDestroyAssetFunction · 0.85

Calls 2

GetLevelSubFunction · 0.85
IsValidMethod · 0.80

Tested by

no test coverage detected