Dynamically spawn actors from class of object?

o/ community,

I just ran into a problem with the blueprint function “Spawn actor from class”, which prevents me from continuing my current project.

To get an idea of what I’m trying to accomplish, here’s a rough scene (numbers will increase, so it has to be dynamic!)

  • I have 2 blueprint actors/classes, a desk and a chair (implementing a furniture interface)
  • the desk is present in my scene, the chair is not spawned
  • I wrote a wrapper blueprint class which holds a furniture blueprint class (e.g. my desk) and calls functions on it
  • one function is, to replace the held blueprint class with a new one (e.g replace desk with chair). To do that, my wrapper destroys the held blueprint actor and spawns a new actor from a dynamically chosen class (e.g. my chair) … atleast this is what I want to do
  • all blueprint actors which should be “spawnable” are stored in an array globally

This is an example of a furniture blueprint actor.

42545-blueprintactor_example.png

And in this screen you see my workflow inside my wrapper class. I pass a object reference to my function and try to get the correct class to spawn an actor of it. The object itself will differ, but it will always be a blueprint class.


The 1st problem I encountered was, that getClass provides a “Object Class” but Spawn Actor requires an “Actor Class”, so I cant plug this class into the spawn node.

That lead to this final problem:

it seems like I’m unable to get/cast an actor class of my object to dynamically spawn an actor, because the cast always fails.


As you can see in the screen shot I already double checked if my object is valid / expected blueprint, and also tried to get the class from a static object chosen in a getClass-node.

However, I have no clue how to retrieve the actual “Actor Class” required to spawn my actor.

If I choose the class of my blueprint in the dropdown menu of the Spawn Actor node, everything works fine. But because the passed object changes, I can’t stricly choose one class.

I also don’t want to iterate over my whole array of blueprints and compare my object to all of them over and over and switch on that.


Is there any way to get the correct class to spawn actors dynamically? Am I missing something crucial? Please guide me into the right direction!


PS: Some peeps already asked similar question on answerhub, but noone offered a solution to solve the with dynamic spawning problem.

1 Like

Thanks to #unrealengine irc-user Liine I managed to solve my problem, by changing the type of my array to “Actor Class”. By doing that, I was still able to pick the right assets of my furniture (by adjusting my function
calls), but also directly had the right type, to spawn from.

Even tho i wasn’t able to explain why a usual getClass and a cast do not work, it fixed the problem and made my project even more overseeable.