How to programmatically add a component to an actor blueprint within an Editor Plugin?

Does AddActorComponent return a component or nullptr?

It returns the instanced class object, which seems correct. But the target actor doesn’t get anything when I check.

You should be able to pass in any level actor as WorldContextObject as well, worth testing.

Didn’t make a difference sadly

Source code for AddComponent and related methods are in Actor.h and ActorConstruction.cpp.

So I found the definition for AddComponentByClass in ActorConstruction.cpp. However this function isnt used anywhere within Engine\Source\Editor. So I assume the green “Add component” button in the Blueprint editor uses something else. There is something called UK2Node_AddComponentByClass. But it doesn’t seem to be used anywhere relevant either.

I’m still trying things with the bits of code you sent, but my engine keeps crashing when I try it so nothing for now