[C++] Access BP Parent Class Members

Hi all,

If I have a simple POD class like such:

UCLASS(Blueprintable)
class USimplePod : public UObject
{
   GeneratedBody()
public:
   int32 GetMySimpleVar() const { return MySimpleVar; }
protected:
   UPROPERTY()
   int32 MySimpleVar;
};

And I have a custom C++ Blueprint object (inherits from UBlueprint, has a custom factory, etc) that has USimplePod as the Parent Class. How would I access/modify the members of the Parent Class from the Blueprint object?

The only answer I found was to do something like:

USimplePod* MyPod = Cast<USimplePod>(MyBlueprint->ParentClass->GetDefaultObject());
// Set the members, etc.

But, if I understand things correctly (which might be a stretch), wouldn’t that just be editing the Class Default Object of the Parent Class (in this case, USimplePod)? Beyond that editting the CDO sounds like a terrible idea, I could have N number of these BPs so they each need their own “copy” of Parent Class members they can customize, etc. The ParentClass is just data, no runtime craziness so I believe this should be totally possible.

Any thoughts?

EDIT: I figured it out. What I wanted was the CDO of the GeneratedClass and not the ParentClass. Cheers!

If your “MyBlueprint” is not a reference (MyBlueprint*) and assuming you have not spawned the blueprint in already, Just spawn it in:

USimplePod* MyPod = NewObject<USimplePod>(MyBlueprint->ParentClass); 

This should work, although you may have to play around with the parameter, because I have only referenced blueprints from the TSubclassOf and spawned them in that way.

Thanks for the reply, Joel.

I think that would create a whole new object of type “ParentClass”, and not alter the members that were inherited from ParentClass which is my goal.