How do I convert TSubclassOf to AClass?

I have a custom class AItemBase, and a TArray> I use to hold every unique actor blueprint I make from this class. Whenever I pick up or otherwise use items from this database, I need to convert the array’s value back to AItemBase, so I can access methods in the default base class. I tried casting:

TSubclassOf<AItemBase> tempSubclass;
AItemBase* baseClassRef = Cast(tempSubclass);

However, this doesn’t seem to work, as the cast never succeeds and baseClassRef always remains empty. I’m assuming that’s because tempSubclass is a Reference, and baseClassRef wants an Instance… I don’t need to spawn tempSubclass into the world, but I do need to run methods from it- is there an alternative to Cast, or is what I’m describing fundamentally silly?

Edit to add: I’ve found that I can get an actor by running this:

baseClassRef = tempSubclass->GetDefaultObject();

I can call refs on the base class, but it doesn’t retain any customization I apply to the blueprint: if I give SomeItemBP two custom components in the editor and set tempSubclass to that BP, tempSubclass->GetDefaultObject(); doesn’t have any of the components I added.

AItemBase* DefaultBaseClassRef = tempSubclass->GetDefaultObject();

Ack, you beat me to it! :slight_smile: This is exactly what I needed… I don’t suppose there’s any way to make GetDefaultObject return with the modifications/extra components I added to the actor blueprint before compiling, is there?

To clarify, as I just re-read that comment and realized it’s not particularly clear, what I was getting after was this: I have a component UMorpheme, and every subclass of UMorpheme contains specific item functionality: consumables, weapons, and equipment are all created by adding different UMorpheme subclasses to an actor blueprint of ItemBase in the editor, then adding the complete blueprint to my array. When I access it with GetClassDefaults, however, all of the morphemes are stripped off, and the class only has access to components I created in the class constructor, and not the editor.

You can spawn it, then call your methods or gather components.

Alright, thank you very much! :slight_smile:

TSubClassOf::GetDefaultObject doesn’t exist in my case, was it renamed?