# How to delete an asset from Editor in C++?

**URL:** <https://forums.unrealengine.com/t/how-to-delete-an-asset-from-editor-in-c/453710>\
**Category:** World Creation\
**Tags:** Destroy, unreal-engine, Physics, editor, CPP, question\
**Created:** [August 11, 2019, 4:13pm UTC](https://forums.unrealengine.com/t/how-to-delete-an-asset-from-editor-in-c/453710 "2019-08-11T16:13:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![1st-ICEMAN](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@1st-ICEMAN](https://forums.unrealengine.com/u/1st-ICEMAN)\
**Post date:** [August 11, 2019, 4:13pm UTC](https://forums.unrealengine.com/t/how-to-delete-an-asset-from-editor-in-c/453710/1 "2019-08-11T16:13:15Z")

</div>

Hello,  
  
I wanna delete a bunch of assets inside the Editor (content browser) with C++ code. I already tried calling:

```
UObject* object = ... ;
object->ConditionalBeginDestroy();
GEditor->ForceGarbageCollection(true);

```

but that leaves an empty asset behind (called ‘NONE’).  
Any ideas how i could do this properly?

---

<div class="post-metadata">

**Author:** ![1st-ICEMAN](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@1st-ICEMAN](https://forums.unrealengine.com/u/1st-ICEMAN)\
**Post date:** [August 12, 2019, 2:27pm UTC](https://forums.unrealengine.com/t/how-to-delete-an-asset-from-editor-in-c/453710/2 "2019-08-12T14:27:40Z")

</div>

Took me some time to figure it out, but i think you can not instantly destroy/ delete Assets (or any subclass of UObject). Instead you can mark it as “pending kill” and the garbage collector will pick it up eventually. I did it by simply calling this function:

```
object->MarkPendingKill();

```

Additional hint:   
  
forcing the garbage collector to do its work by calling ForceGarbageCollection(true) apparently is not a good idea, as it caused the editor to crash, due to some assets being a “nullptr”.

---

<div class="post-metadata">

**Author:** ![Anonymous\_dc35b1f8e3e9594cc41d6f8f659a166d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anonymous\_dc35b1f8e3e9594cc41d6f8f659a166d](https://forums.unrealengine.com/u/Anonymous_dc35b1f8e3e9594cc41d6f8f659a166d)\
**Post date:** [October 23, 2020, 3:32am UTC](https://forums.unrealengine.com/t/how-to-delete-an-asset-from-editor-in-c/453710/3 "2020-10-23T03:32:55Z")

</div>

And then, u need use

> `FAssetRegistryModule::AssetDeleted( AssetData.GetAsset() ) ;`

to delete the Asset !

---

<div class="post-metadata">

**Author:** ![fh9501](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@fh9501](https://forums.unrealengine.com/u/fh9501)\
**Post date:** [May 24, 2021, 9:05am UTC](https://forums.unrealengine.com/t/how-to-delete-an-asset-from-editor-in-c/453710/4 "2021-05-24T09:05:09Z")

</div>

ObjectTools::DeleteAssets(AssetsToDelete);

---

<div class="post-metadata">

**Author:** ![MasterKainAG](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MasterKainAG](https://forums.unrealengine.com/u/MasterKainAG)\
**Post date:** [May 1, 2024, 5:23am UTC](https://forums.unrealengine.com/t/how-to-delete-an-asset-from-editor-in-c/453710/5 "2024-05-01T05:23:44Z")

</div>

> [@1st-ICEMAN](#):
>
> ```auto
> object->MarkPendingKill();
> 
> ```

Is it possible to prompt the delete screen which shows references?
