Add an object from a subclass in a master blueprint for its subclass?

Ok so this is a bit tricky, maybe i just don’t fully understand how object oriented programming works in UE4 so i will just include the blueprints.

I have this “Shrine” blueprint class that i have created. Part of the shrine class is a component variable for a “Powerup” class, with its own set of subclasses for different powerups. In this specific instance, “Shrine Master” has a subclass “Fire Shrine” which is to be associated with the “Powerup” subclass “PowerupMega”. But Shrine Master needs to grab one of these subclasses on startup and assign it to a variable like so:

Except even though the object reference is WORKING when i use “add powerup master” i can’t specify parametrically in the child class WHICH subclass of powerup master i want it to add. There IS a node “construct object from class” that outputs the type of variable i’m looking for, except that it has a runtime error “cannot construct objects of class”… and i’m guessing in this context “construct” is not the same thing as “add”.

The best strategy i can think of right now is to have the Shrine object contain 2 variables, one containing the parameterized powerup subclass and the other containing the actual object reference, and on construction assign an instance of the subclass to the object reference variable. Except i don’t know the right node to use for this.

As you can see below, the “Powerup Class” field basically has the behavior i want, except i want to feed that into the variable declaration in the construction script above.

I’m not quite sure I understand what you are doing here.

If the fire shrine is always going to have the PowerupMega variable set directly into its blueprint, why do you need to also assign it the PowerupMega variable inside the shrine parent class?

Because I need it to be both dynamic and parametric. And the Shrine Parent Class SHOULDN’T be assigned powerupmega… it should be assigned a reference to the powerup parent class that can be further specified in its child classes. Nor do i want the Fire Shrine to ALWAYS be assigned PowerupMega, just that by default.

After doing a bit more digging it looks like the node i am looking for is “Add Component From Class”… Which apparently straight up doesn’t exist. I also found out the reason “Construct Object From Class” doesn’t work on components is because it doesn’t work on anything that derives from the Actor class. Even though actors all still technically derive from the object class.

As far as i can tell, i am looking for functionality that just doesn’t exist with blueprints, unless someone can give me a workaround.

Very possibly I’m missing the point here but…

So I made some BPs:

Mana station

Powerup with 2 child BPs

Powerup child 1 and 2

Then in the mana station, I can say:

Yeah but the problem with that is that its a class reference, not an object reference so it doesn’t give me access to its properties. I need that class reference to instantiate as an object reference and plug that into my powerup object reference variable. I don’t need to set my class reference variable on construction, i can just do that parametrically in the details panel.

Ok, but it you make the variable of type power-up, then you could do it with a cast to the child, no?

( still accept I might be missing something… )

Apparently if you’re working with a class reference the only thing you can cast to is a class reference. Believe me, I’ve tried.