C++ Access To Variables Using Reflection

I am trying to access the UProperties of Blueprints using reflection. I can access them, it appears, if the property is a class, but not a simple variable type (bool/int/struct, etc.). For example, if I create a Blueprint and add a Dynamic Material Instance property, it shows up in the list of properties for the class. However, if I create a simple LinearColor or float as a variable on the Blueprint, it doesn’t show up. How to access these variables using reflection?

Thanks!

This is all in C++, by the way, I need to be able to enumerate the variables of a Blueprint in C++ using reflection, including simple variable types.

I haven’t looked into it, but are your properties on your blueprint public? That might affect your ability to see them through UProperty.

Another thing I might try is to try casting your UProperty into a UNumericProperty and see if it’s valid. And for the LinearColor try casting to UStructProperty. There’s also a UBoolProperty for bools.

I’m sure there’s a more elegant solution than to try casting and seeing if they are valid, but I thought I’d give you some things to try.

Hi Embeddetech,

When accessing a variable that has been created in the blueprint editor in C++, you’ll need to access them by the name of the UProperty, and then use ContainerPtrToValuePtr to do anything with them. You can find more information about ContainerPtrToValuePtr here:

https://docs.unrealengine.com/latest/INT/API/Runtime/CoreUObject/UObject/UProperty/ContainerPtrToValuePtr/1/index.html

Hope this helps!

Hi ,
Thanks for the support! I in general won’t know what the name of the property is, and am trying to use the reflection system to generalize the solution (I’ve verified that this is indeed what I need, not a kludgy way of doing what I’m needing to do). So what I am currently doing is getting an object’s StaticClass, then getting its PropertyLink, and iterating through the PropertyLink linked list I can get the name of the field using the PropertyLink->GetName() function. However when I use this approach, my structs and primitive elements (floats, ints, etc.) don’t show up. Is there another way to find these properties?

Also, if I were to access them by the name of the UProperty, what’s the right way to do that?

Thanks!!

Hi Zaucy,
Thanks for the response! I believe the initial problem I am having is getting a reference to the property, currently I am taking an object, getting its StaticClass(), and then enumerating through the static class PropertyLink linked list. I can get the name of each property on this list, and the LinearColor and other primitives don’t show up in this list. Just objects like DynamicMaterialInstance variables or StaticMesh components.

I believe, trying to do what you’re trying to do, it would be much easier and much less of a hassle if you were to declare these UProperties in the C++ class that these blueprints are based off of instead of trying to refer to variables that have been created inside of the blueprints themselves. This would allow for much more versatility and less overhead overall.

If you do wish to stick to this method however, you should be able to find the name by using a pointer to a UProperty and using FindPropertyByName.

Hi ,
I was able to get at, there were a couple of things I was doing wrong. First, I wasn’t using the TFieldIterator class, when I went to that I was able to get all of my fields. After that, I was able to use the UProperty’s GetCPPType reflection capabilities to at least get the name of the property’s type. I think that should be good enough for my purposes.

Thanks again!