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.
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:
ParentInstance->MyArray[0];
If the array is private and you created the getter you should be able to access it through:
TArray<int> MyArray = ParentInstance->GetMyArray();
MyArray[0];
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.