Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Add component to actor?


Working on a plugin, and am wondering if anyone knows how to add a component to an AActor from C++? I saw many ways to do this procedurally and dynamically during runtime, but no examples outside of runtime. Specifically, how would I use FObjectInitializer::CreateDefaultSubobject when a) Not in runtime (during editor mode) and b) the class doing the component creation is not the class I want to add the component to (Ive simply got a reference to the world actor where I want to add a reference)

Product Version: UE 4.12
more ▼

asked Jun 07 '16 at 05:17 AM in C++ Programming

avatar image

60 10 15 19

avatar image LumenArtisan Jun 17 '16 at 05:26 AM

Hi Penanito. Did you ever find a way to do this? I have a similar problem and would like to automate adding static and skeletal meshes to an actor in the Editor... NOT at runtime. Here is a link to my question.

Surely there's a way to do this programatically in the Editor, but so far I haven't found a way to access the AActor BP to add components to it without creating an instance of it in the game. Yet we can do exactly this in the Editor using the GUI. I just want to automate that process, and it sounds like you might be looking to do something similar for your plugin.

Any leads?


avatar image Penanito Jun 17 '16 at 05:53 AM


Originally, I was going to create an 'Editor Only' Skeletal mesh to display some stuff for the game's developers, and add that mesh to already existing world actors, but now Instead I'm simply creating a new Editor only actor that already has a SkeletalMeshComponent, and instead will spawn this editor only actor when the editor is finished loading. So unfortunately I stopped trying to figure out dynamic addition of components in-editor (though it definitely should be possible)

One thing I will note though, that might be of help to you, is that you can call regular Blueprint functions from C++, not necessarily Blutilities, during editor mode. I attempted with Blutilities and they were very experimental and I found this method to work better. for C++ -> Blueprint communication:

FEditorScriptExecutionGuard ScriptGuard; { BlueprintInheritedClass->EditorFunction(); }

where BlueprintInheritedClassis a reference to any runtime C++ class, that is inherited by a Blueprint. And EditorFunction() is a BlueprintNativeEvent that is overriden in BP:

UCLASS() class BlueprintInheritedClass { public: UFUNCTION(BlueprintNativeEvent) returnType EditorFunction(); // }

Pretty much what FEditorScriptExecutionGuard lets you do is run Blueprints in editor mode. Not sure if you can even add skeletal meshes dynamically through Blueprints (during runtime), I dont blueprint at all, but if you can, then you should be able to create a BP C++-callable function that adds all of these skeletal and static meshes, add your empty object(s) in your world, loop through all your world objects of this type in C++, get their reference and call their EditorFunction()

avatar image LumenArtisan Jun 17 '16 at 03:52 PM

Thanks Penanito! I was unaware of the whole FEditorScriptExecutionGuard concept, so I'll toy around with this and see if I can make any progress.

avatar image Nintari Aug 31 '16 at 03:55 PM

I am looking for a way to do this as well--trying to generate the equivalent of "prefabs" by importing a collection of static meshes into an Actor.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question