I am trying to dynamically create an object at runtime from a BP class which is derived from a C++ class. The BP class declaration only changes the value of an integer member variable called TestVariable. When I print the value of this variable on the newly created object, I expect it to print the value set in the BP declaration but it instead prints the default C++ class value.
I suspect that line 3 of the included code creates an object of the ParentClass rather than the child class. Is there somehow a limitation in the engine regarding this or am I overlooking something silly?
Edit: This is a modified version of the snippet only changing variable names and removing log statements, but the original version does print “BP_InventorySlotContainerBox_C” (BLUEPRINT classname) as expected.
Edit 2: To my knowledge I am following all the steps outlined in this solution: How to instantiate BP class in C++ - Blueprint - Epic Developer Community Forums
if (ClassToCreate)
{
CreatedObject = NewObject<ParentClass>(ClassToCreate);
if (CreatedObject)
{
UE_LOG(LogTemp, Warning, TEXT("Box %i"), CreatedObject->TestVariable);
}
}