How to get variable of a blueprint in c++?

I create a variable in a blueprint, and in my c++ code, I get the BP class using code as follows:

static ConstructorHelpers ::FObjectFinder<UBlueprint> assetObject(TEXT(  Blueprint'/Game/Blueprints/TestTest'" ));

    if (assetObject.Succeeded())
        TestBlueprint = ( UClass*)assetObject .Object-> GeneratedClass;

I know how to call a function using spawnActor, * FindFunction * and ProcessEvent. But I have no idea how to get the variables in a blueprint.

Moreover, if the function has a return value, how to get the return value in C++ code?

If anyone has any idea about the question, please let me know.


to access a variable from both c++ and blueprint, the variable needs to be made in c++.

To do this from C++ is not the easiest thing. It’s not hard (tricky yes and possibly crashy), but there’s more code involved than a GetFoo() call.

First, you need to get the UClass for the object in question. Then you need to find the UProperty object of the variable, which contains the memory layout information for the class. Once you have that, you can use CopyCompleteValue() to copy the data from the instance of the object into an item of that type.

It can be done, but I recommend you look for an easier solution like an event or make the variable native

Actually, I created a function that get a reference of the value, and change it inside the blueprint function.

Can you post example code for this please? : )