Spawn Blueprint by String/Path

I want to spawn a Blueprint actor using its name/path. For example, I have a Blueprint named “Blueprint1” and I want to spawn that Blueprint based upon the string “Blueprint1.”

How can I parse a string to return a Class or Object type?

Is it possible to do this with BPs or should I start thinking about a C++ method?

Funny how I literally had this exact same question today. Sorry that I can’t help you, but I hope someone answers it for us!

Brianpow, in your particular case would it be acceptable to just hard-code a map structure that uses strings as the keys (blueprint names or paths) and class references as the values and then just do a lookup on from that structure to determine which BP class to spawn?

you wanna spawn that blue print with a string or your wanna spawn
writing string ?

Spawning a blueprint actor given an Unreal local path. Like if the blueprint is in a folder called BP, and if the Blueprint is called Ball, how do you spawn an actor of the blueprint given the string BP/Ball? Is this possible?

Krxtopher, how would you store a map in Unreal? Is there an actual data structure defined, or do you just mean to have a function that, given a key of a string name, returns a reference to the class?

i create a video check is this and
tell me if that’s what you want or not xD :slight_smile: i duplicate the projectile , material and change the mateal color of second material ball. Unreal Engine 4 Answerhud Spawn diferent actors class with a string Names - YouTube

I’ll type up a detailed answer tomorrow, but if the suspense is killing you I can tell you in brief that you won’t have to touch C++! You’ll create a custom Structure (Content Panel > Add New > Blueprints > Structure), and you’ll create a Data Table (Content Panel > Add New > Miscellaneous > Data Table) in which the row names are your blueprint names and the row contents are your struct instances which each hold a reference to the actual blueprint classes.

That would be fantastic Krxtopher!

If it helps, I will elaborate on my situation.

I am actually reading in a CSV file and grabbing the strings (names) and I have named the Blueprints the same as the strings pulled from the CSV.
Right now I have settled on building a giant enum with all the blueprints and I switch on enum from the data struct where I store all the CSV data.
If I could take the name string extracted from the CSV file and use it to load a blueprint right now I would rather do that the enum, even though I’m not sure what best practices would be as far as resources.

A function along the lines of SpawnActor, but instead of spawning based on a class type it spawns based on the class name. Can I parse a string into a bp class?

Furthermore, I only need one instance of each, each is unique and none will be used/visible simultaneously.

To create a lookup table that maps string names to class references you can use a custom Structure asset and a custom Data Table asset. Here’s how to do that…

Create a new Structure called “ActorClassStruct” (Content Browser > Add New > Blueprints > Structure).

Open the ActorClassStruct for editing.

The structure will have a single default property named “MemberVar_0” of type Boolean. Rename this to “ActorClass” and set its type to “Actor > Class”.

Save and close the structure.

Create a new Data Table called “ActorClassesDataTable” (Content Browser > Add New > Miscellaneous > Data Table). When asked to pick a structure to base your data table on choose the ActorClassStruct you created above.

Open the ActorClassesDataTable for editing.

In the Row Editor panel, click the “+” to add a new row. Then name the row (top right “Row Name” field) to something like “Blueprint1”. This will be the string you use in your code to look up the actual actor class.

Under the “Row Value” section for your row you will see an “ActorClass” property. Open the dropdown next to this property name and select the actual “Blueprint1” class.

Keep adding rows for each of the classes you want to be able to reference.

In the screenshot below I’ve demonstrated one way you can use this data table. This is an actor blueprint I’ve called “Container_BP” and placed in my level. At runtime the Container_BP looks up my Blueprint1 class by the string “Blueprint1”, spawns it, and then attaches it as a child.

1 Like

This is not exactly what I wanted, I wanted to avoid building a lookup table, but it is definitely better than what I intended to do with enums. I think for what I initially wanted I would need to write something in C++ that parsed a string into a function/variable get parameter, but I’m just not experienced enough with the compiler to go down that path during production.

Thanks for this, it will definitely solve my problem!

The marked answer isnt really right. I was looking for the same thing and figured it out.
To reference a Class just type the name of the BP and add “_C”
A simple way to make sure, and how I figure it out, is to:
-Add the object to your level
-Add a reference on a BP or Level BP
-Plug it to “Get Class”
-Plug that into a print node
-Play the game and you’ll get your answer.
This way you can check what ever object you want. Im loading classes through a CSV and worked perfectly.

The marked answer isnt really right. I was looking for the same thing and figured it out.
To reference a Class just type the name of the BP and add “_C”
A simple way to make sure, and how I figure it out, is to:

-Add the object to your level

-Add a reference on a BP or Level BP

-Plug it to “Get Class”

-Plug that into a print node

-Play the game and you’ll get your answer.

This way you can check what ever object you want. Im loading classes through a CSV and worked perfectly.

You are a miracle worker!!! You literally saved my project.
Now is it possible to put many data tables on the same blueprint?