Adding component to Actor in Editor

Salute!

I add a component to an Actor on scene through the function (shown below). Idea works, but there is an unpleasant nuance that I want to solve.

When I click button that will create/register/attach a component to an Actor, everything works, except that the component DOES NOT DISPLAY in that Actor Details panel. As soon I deselect this object and select it again, the component is correctly displayed where it should be.

How to change this behavior? After all, if I simply add a component via "+ Add ", then Details panel displays everything at once. Do I need to look for some “data update” function in some Slate-class or is there an easier way?

Now I will click on highlighted button (Add Cutter) to add a comp.

After clicking on button, BoxComponent is added (and visible on the scene), but it is not in the Details panel!

I deselect the object and select something else…

…then I select the cube actor again and BoxComponent is displayed correctly in the hierarchy of this actor.

Function code

I’ve just faced the same problem and solved it in C++ like this:
image

Basically you deselect everything and select your Actor again.

1 Like

The deselecting & reselecting workaround no longer seems to work in UE 5.1.1

:frowning:

1 Like

Hmm, strange, but I have no problem with solution from above, but this is only my case.

If you need to instantly deselect an object after a certain action or you need to update the Viewport state, then you can try another way:

#if WITH_EDITOR
	USelection* Selection = GEditor->GetSelectedActors();
	Selection->Deselect(this);
	FViewportClient* ViewportClient = GEditor->GetActiveViewport()->GetClient();
	ViewportClient->RedrawRequested(GEditor->GetActiveViewport());
#endif

Details:

  • USelection requires # include “Selection.h”
  • you may need to # include “ViewportClient.h” for FViewportClient
  • Selection->Deselect(this) - in my case, I deselect the object in which this logic is written, but you need a pointer to the object from which you deselect
  • if anything, then this is also possible: Selection->Select(pointer to UObject), if you need it
  • main method here - RedrawRequested(), if your goal is the same task that I had when created this post
FLevelEditorModule& LevelEditor = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
LevelEditor.BroadcastComponentsEdited();