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"

Access blueprint components from c++


I am working on a small plugin for the unreal editor and i need to have access a blueprints components from c++.

What I want is basically access to the variables in the components of the blueprint currently open in the blueprint viewer ( all the components in the blueprints component tab ).

So if I have, for example, a character blueprint containing a character movement component and a camera component I want to be able to access for example the "field of view" float value in the camera settings or the "Jump Z Velocity" float value in the character movement component from the c++ code.

Is this possible? I might add that i only want to read the values, not change any of them if that makes a difference.

I have access to the current blueprint as "UBlueprint* bp" and from other questions here I read that if I have a Actor pointer it is possible to call GetComponents that will return a list of components, is this what I am looking for? and if it is, how do I use this with my UBlueprint pointer?

Many thanks in advance.

Product Version: Not Selected
more ▼

asked Mar 06 '15 at 12:56 AM in C++ Programming

avatar image

16 3 4 5

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

2 answers: sort voted first

The correct way to do this would be to first create a C++ class, than create a blueprint from that class.

For example, you create a class names ClassA. You specify that class to be Blueprintable by using the Blueprintable specifier in the UCLASS macro when defining your class.

Then, in the editor create your Blueprint from ClassA. Let's call it ClassA_BP for this example.

One way to do it would be to create your component (like your movement component) directly in the C++ class using the ObjectInitializer (Or the PCIP if you are on a version of Unreal earlier than 4.6). If you really want to create the components in your Blueprint and then "get" them in your C++, then yes, the way to go is to use GetComponents().

Something like this : (I'm writing from memory, so the syntax may be wrong)

 TArray<UMoveComponents*> allMoveComp;
 for(int32 i = 0; i < allMoveComp.Num(); i++)
     //Do whaterver you want here with the components...
more ▼

answered Mar 06 '15 at 01:56 AM

avatar image

2.1k 70 38 259

avatar image LinFredriksson Mar 07 '15 at 02:48 AM

The plugin should work with any blueprint so i do need to create the components in the blueprint and then get them in C++. So then GetComponents() is what i want, great. But if I have a blueprint pointer how can i use this function? If I have a character blueprint, how do I get a AActor from that I can use to call GetComponents() ?

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

I'm not certain this is the correct way, but I'd try getting the CDO as follows:

 Blueprint->GeneratedClass->GetDefaultObject< AActor >() ;

Hopefully, if it's an actor blueprint, that should return a valid pointer to the default object for the blueprint's class, from which you can access the values.

more ▼

answered Mar 07 '15 at 09:26 AM

avatar image

2.1k 83 37 121

avatar image LinFredriksson Mar 09 '15 at 03:03 PM

Yes, this does give me all the default components, so it is a big step in the right direction. But i need to access all of the components in the current blueprint not only the default components and i have not yet figured out how to do this. Then off course i need to figure out how to access the values inside of these components, but one step at a time for now.

avatar image kamrann Mar 09 '15 at 09:58 PM

I'm not sure what you mean by 'default' components. I haven't tested it, but the CDO for a blueprint should have all components which you can see in the components tab instantiated for it. Then you can access their values by either casting, or, if you don't want to make any assumptions about the types of components, you can call GetClass() and then iterate over the properties.

You might also need to be aware that the CDO will only reflect the state of the blueprint at the point it was last compiled.

avatar image LinFredriksson Mar 10 '15 at 12:28 AM

With 'default' components I meant the components that exist by default when I create for example a character blueprint. Any components i added later to the blueprint did not show up. But i figured out how to find those components in another day. I also managed to access the values so now I think that I have everything I needed. Thanks for the answer.

avatar image zamy Apr 22 '15 at 03:10 PM

How did you do that man? i'm stuck on this too. Any suggestions?

avatar image phil.harlow Sep 16 '16 at 09:43 PM

I am also looking for a solution to this. Could you share the workaround you found?


avatar image soulsource_ag Aug 10 '18 at 12:10 PM

While the asset is being edited, you might have luck accessing the editor's preview instance using Blueprint->SimpleConstructionScript->GetComponentEditorActorInstance()

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
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