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.
asked Mar 06 '15 at 12:56 AM in C++ Programming
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)
answered Mar 06 '15 at 01:56 AM
I'm not certain this is the correct way, but I'd try getting the CDO as follows:
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.
Follow this question
Once you sign in you will be able to subscribe for any updates here