How do I get a reference to blueprint variables in c++?

I have created a blueprint and defined a couple of variables inside. I wish to reference some of the variables inside c++ code and possibly manipulate them, is there a way to do so?

My attempt so far is to cast a BlueprintObj to a UBlueprint pointer, but I have no idea on how to reference a variable inside that blueprint.

I know I could just create the class with the variables I want in C++ and make a blueprint out of it to access its variables there aswell by using the uproperty, but is there a way to do the opposite? Create a blueprint with variables then somehow reference them in code.

UBlueprint is an editor only time concept, once you’ve cooked the game the UBlueprint no longer exists. Instead the generated blueprint class as far as UE4 is concerned is just like a C++ class, at least in terms of how it’s laid out in memory. You could attempt to set values using reflection, setting it as a T3D formatted string, but I wouldn’t recommend it. You’d need to use the FieldIterator/FindField to locate the property on the class object returned by GetClass on the object.

The expected approach is for you to create it in C++, and then inherit the blueprint from it. Alternatively, expose a function in C++ that the blueprint could call passing its data.

Cheers,
Nick

Thanks, the FindField function was what I was looking for :slight_smile: