# "Call in Editor" Add Component, Delete Component

**URL:** <https://forums.unrealengine.com/t/call-in-editor-add-component-delete-component/563407>\
**Category:** Pipeline & Plugins\
**Tags:** Editor-Scripting, unreal-engine, UE4-27\
**Created:** [May 22, 2022, 12:54pm UTC](https://forums.unrealengine.com/t/call-in-editor-add-component-delete-component/563407 "2022-05-22T12:54:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wab11](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@wab11](https://forums.unrealengine.com/u/wab11)\
**Post date:** [May 22, 2022, 12:54pm UTC](https://forums.unrealengine.com/t/call-in-editor-add-component-delete-component/563407/1 "2022-05-22T12:54:08Z")

</div>

How to Add Component inside “Call in Editor” Function ?

When I “Add Component by Class” node inside “Call in Editor” with simple “Sphere Collision” - I see on the Scene in Called Actor Sphere is showing up !  
But in components list it does not appear ! And if I move a little this Actor, Sphere disappear !

In the other way, If Actor has by default Component Sphere and inside “Call in Editor” function with GetComponentsByClas-\>“For each Loop”-\>DestroyComponent, it tell me in “Output Log”: “Error: May not destroy component SphereComponent…”.

The same happen if my Actor hasn’t SphereComponent but I Add it by “Call in Editor” function and then destroy all components returned by GetComponentsByClass. I have errors on old Components not destroyed properly “Error: May not destroy component SphereComponent…”

Anyone know is it possible to Add/Delete Component to Actor in “Call in Editor” function ?

Edit:  
Possibly duplicate (post without solution):

> [@\[Editor Utility\]Adding component to actor in level](https://forums.unrealengine.com/t/editor-utility-adding-component-to-actor-in-level/479753/2):
>
> If you made your actor component in the editor that did not work for me either… if you add component to any actor in a level and make a blueprint or C++ script component off of it that runs through setting up a new class that inherits from Actor Component wasn’t able to find a different in editor option to make a blueprint script component so there’s probably another way, if you find it would love to know, but that should work for ya [344220-editorcomp.png]

---

<div class="post-metadata">

**Author:** ![wab11](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@wab11](https://forums.unrealengine.com/u/wab11)\
**Post date:** [June 14, 2022, 8:03am UTC](https://forums.unrealengine.com/t/call-in-editor-add-component-delete-component/563407/2 "2022-06-14T08:03:07Z")

</div>

I solved this problem by inherit from SSCSEditor and call method “PerformComboAddClass”. This function can add visible component like after click green button “Add Component”.

---

<div class="post-metadata">

**Author:** ![Ldwork\_Gamedev](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ldwork_gamedev/32/886560_2.png) [@Ldwork\_Gamedev](https://forums.unrealengine.com/u/Ldwork_Gamedev)\
**Post date:** [September 10, 2022, 1:38pm UTC](https://forums.unrealengine.com/t/call-in-editor-add-component-delete-component/563407/3 "2022-09-10T13:38:31Z")

</div>

Can you give some sample code of how you did that. I’ve been struggling with this for a while now. Thanks in advanced.

---

<div class="post-metadata">

**Author:** ![wab11](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@wab11](https://forums.unrealengine.com/u/wab11)\
**Post date:** [September 11, 2022, 11:17am UTC](https://forums.unrealengine.com/t/call-in-editor-add-component-delete-component/563407/4 "2022-09-11T11:17:42Z")

</div>

Yeah, Epic in unknown reason try to take away from us possibility to use same functionality as in editor (green button Add Component).

First you need to create new class (.h file):

> #if WITH\_EDITOR  
> #include “SSCSEditor.h”
> 
> class CONTROLPOINTSRUNTIME\_API SEdit : public SSCSEditor  
> {  
> public:  
> UActorComponent \* DoAddComponent (UObject \* obj, UClass \* ComponentClass);  
> };  
> #endif

and .cpp file:

> #if WITH\_EDITOR  
> extern UNREALED\_API UEditorEngine \* GEditor;
> 
> UActorComponent \* SEdit::DoAddComponent (UObject \* obj, UClass \* ComponentClass)  
> {  
> SelectRoot ();  
> return PerformComboAddClass (ComponentClass, EComponentCreateAction::SpawnExistingClass, nullptr); /// Protected method need to be Run in Child of SSCSEditor Class  
> }  
> #endif

Second you add to your custom actor or blueprint function library this function (.cpp file):

> UActorComponent \* UBPL::AddComponentInEditor (UObject \* BlueprintAsset, UClass \* ComponentClass)  
> {  
> UActorComponent \* Comp = nullptr;
> 
> #if WITH\_EDITOR  
> if (GEditor)  
> {  
> if (BlueprintAsset)  
> {  
> GEditor-\>SelectActor (dynamic\_cast\<AActor \*\>(BlueprintAsset), false, false, false, true); /// Refresh Actor instance - Unselect Actor
> 
> ```
> TSharedPtr<SEdit> sedit;
> sedit = SAssignNew (sedit, SEdit)
> .EditorMode (EComponentEditorMode::ActorInstance)
> .ActorContext (dynamic_cast<AActor *>(BlueprintAsset));
> Comp = sedit->DoAddComponent (BlueprintAsset, ComponentClass);
> 
> sedit.Reset (); /// Remove Shared Pointer Reference. Because it is only one reference, Object "sedit" is destroyed.
> GEditor->SelectActor (dynamic_cast<AActor *>(BlueprintAsset), true, true, true, true); /// Refresh Actor instance - Select Actor 
> };
> 
> ```
> 
> };  
> #endif
> 
> return Comp;  
> }

This code take me many days to dig into Editor code and many trials.  
This code concern UE 5.0.3.  
For UE 4.27.2 code different a little.

I think Epic guys should expose this function for programmers in some kind of API. Same as many others functions and do not force developers to use tricks.

@Ldwork_Gamedev wish you good code 🙂

---

<div class="post-metadata">

**Author:** ![PDubulous](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/pdubulous/32/1194655_2.png) [@PDubulous](https://forums.unrealengine.com/u/PDubulous)\
**Post date:** [April 2, 2025, 9:35pm UTC](https://forums.unrealengine.com/t/call-in-editor-add-component-delete-component/563407/5 "2025-04-02T21:35:59Z")

</div>

This works in 5.3. The general idea is here, you’ll just need to adjust it

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/9/c/19c858641ac25cd8d0ab4e96d0ba4b99be9920d3.jpeg)

[Editor Utility for adding an Actor Component to an Actor posted by PDubulous | blueprintUE | PasteBin For Unreal Engine](https://blueprintue.com/blueprint/x60_fjrp/)
