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.
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.
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.