Casting from UBlueprintGenerated class

I hate to have to ask a follow up question so soon, but several days ago I asked this question:
Trouble populating and spawning from Subclass Array.

I had wanted to populate an array with blueprints sourced from a particular location in the folder structure and I got a satisfactory answer. All was well, until I found that I wanted to call a function, which required a cast to a class from which my blueprints were derived.

There seems to be a lack of information on UBlueprintGenerated in the documentation, and having perused the available functions within it and its parent class, I can’t seem to find what I need.

I want to do something like this:

Cast<AMyClass>(BlueprintGeneratedClass)->MyClassFunction();

Any help is really appreciated. Thanks!

BlueprintGeneratedClass is UClass pointer you can’t just cast it to actor class, you need to spawn that actor first

  AMyClass* MyActor = Cast<AMyClass>(()->SpawnActor(BlueprintGeneratedClass));

Ofcorse don’t do this in constructor

This is what I worried would be the case, but I had hoped there was a method somewhere from which a class reference could be obtained, similar to UBlueprintGeneratedClass::GetGeneratedClassesHierarchy.

The reason I needed to do this was to get some values from each of the blueprints, and I was hoping to do this whilst filling the array without spawning if possible.

Still, if I was to create an object pool, then this wouldn’t be an issue anyway as I could get the values from the pooled objects, or just simply spawn and destroy them.

Thanks for the response anyway!

Oh you want to access default values? they are in class default object, engine creates one for each class to hold defaults. You can access it via GetDefaultObject() in UClass. Remember to not set anything in it or call functions on it as it might mess up things