Download

Single function to spawn arbitrary class.

Hi, all.

Guys, I need your advice. I don’t know if it’s just me being stupid or what, but I’ve been struggling with this for weeks.

What I’m trying to do is to design a cast system with spells located on HotBars (1 through 9). The basic idea was to spawn each spell actor (which is derived from different classes) using a single function, something like Cast(ClassType* Class) or similar.

Each spell is a blueprint, derived from base C++ class, so the hierarchy is something like this:



ABaseSpell--+
            |__ ASpellDirect (base for blueprint  fireball spell)
            |
            |__ ASpellAOE (base for blueprint blast spell)


So, basically, I need a way to summon Blueprint Actor from C++ function which takes parameters of what BP Class to summon. I know, the solution is somewhat simple, but I’m out of ideas. Still new to UE4.

I think GetWorld()->SpawnActor(…) is what you need…