Casting to Unknown objects

Say that I’m developing turn based combat. I need to transport data between the enemy and the player. Each enemy type is a different blueprint. Every enemy, though, shares the same variables, but with different values. This makes casting difficult, as you cannot “cast to” a blueprint if you don’t know what blueprint it is, regardless if you want to get the same info from two different blueprints. However, if I make all the enemy blueprints children of a parent “master enemy” blueprint, can I say “cast to master enemy” and attach any child blueprint as the blueprint reference?

Yes I believe you can cast to a class higher in the hierarchy,

but another approacc is to use Interface. Many classes can implement the same Interface which is a collection of functions and can be used by ANY class that has it. Each class that implements it can define the same function any way it wants. so you can call that function from anywhere on any class and it will execute in its own way.

Another way is you can use Event Dispatchers with a specific signature to pass along the parameters and in the constructor of each class (or perhaps the parent class - remember to call the Parent versio of the constructor) you just Bind to the event dispatcher and connect en event to it with the matching signature.

Hello!

Yes, this is how inheritance works! If you access base members you don’t need to cast, you can also override base methods in derived classes so you call base methods from base pointers… Polymorphism

But in unreal you can use blueprint intrfaces or event dispatchers for blueprint communication.

When you add an interface to a blueprint you are guaranteed to have the function of the interface added to your blueprint, you have a common interface shared by all blueprint implementing it.

Interface==> one interface function call, the blueprint with interface added react in its own way.

Event dispatcher ==>one event, every blueprint binded react to the call, the others simply ignore the call

Casting instead requires you to know which is the object you are talking to.

Hope it helps!

Beat me to the punch. Polymorphism is arguably my favorite part of object orientated programming.