Efficient way to store data in blueprints to be accessed from C++?


I have an array of unit types that need to be easily modified in the editor, so I set up a blueprint for it, extending the unit type class but I cant seem to access and transfer data from the array in my C++ code. Is there a way to do this? Or is there an easier way for there to be in-editor access to change things in the array?


Somethings i didn’t understand about your question. You created a class in C++ that defines the array of the unit types and you have a blueprint that derives from that class, and you’re having problems accessing the array in C++?

This is a bit confusing as you are extending a class in the editor as a Blueprint. So the blueprint is a child of your c++ class… it’s not possible to read a child variable from a parent class.

Typically, you put the TArray variable in the c++ class, make it blueprint read/writable.

You have a class you made in c++ (extending ACharacter, for example) called MyClass and you want to have an array of objects of a particular type.

In the MyClass.h:

UPROPERTY(BlueprintReadWrite, Category = MyCategory)
		TArray<MyObjectType> ArrayOfItems;

Then you will be able to see this array in a Blueprint that create that extends MyClass.

This is a link to the UE4 function and property MACROs used in the header files.

Edit: Or I completely misunderstood this question.

I dont want it visible from the parent, Im sorry. Im trying to cast the blueprint so I can access it from a seprate class.

I have a blueprint that extends a class with a TArray declaration, with the data for the array stored in the blueprint. I need to access that array from a seperate C++ class, or at least come up with a solution that allows me to add to the array from the editor, and access that array from the C++ code.


Is the array public? If not, try making a getter and see if you can access through it. Make sure you’re casting the blueprint correctly like:

AMyCPlusPlusParent * ParentInstance = Cast<AMyCPlusPlusParent>(MyBlueprintInstance);

If the array is public you should be able to access it through:


If the array is private and you created the getter you should be able to access it through:

TArray<int> MyArray = ParentInstance->GetMyArray();

To test this i would recomend adding a blueprint instance. If the array can be shared between instances you might want to set it to static so you can access it directly through the class.

Do I have to add an instance of the Blueprint in my level or is there a way I can just access it as the array is constant anyway

I had a similar situation, this.

I managed to solve it with a find field function. Get a reference to your non-instanced blueprint and use that function on it and you are good to go.

“Alternatively, expose a function in C++ that the blueprint could call passing its data.”

Perfect, now why didnt I think of that? :l Thanks for the help!

That works too, hope you got it working. Don’t forget to mark the answer so the question is resolved.