How to get assets by name?

Is there a way to get an asset (not currently in the level, but part of the project) by name, using a string?

For example, using the string ‘Someones_Name’ I would like to be able to get a Media Player reference with that name, and then append ‘_Tex_Mat’ to the string (creating ‘Someones_Name_Tex_Mat’) and grab a material using that name.

The reason I’m trying to do this is I have many hundreds of video files that I want to assign at runtime to custom objects. Doing this manually will take ages, so I was hoping to bring in a Data Table full of string names which a function can then read from to generate these objects.

Thus far, I cannot find any way to do this – is this even possible?

A simply Excel formula and your list of names can be a list of assets for usage.

Can you elaborate on that a little? I have successfully imported a list of the asset names from csv into a datatable, so I have access to that list at runtime. But all I have is a list of strings, and I can’t seem to find any way to use those strings to, for example, call up a particular asset (Media Player or Material in this case).

I know I could make an array by hand which had all the Media Players and Materials in, but that defeats the point as adding 500+ objects each to two arrays is the thing I’m trying to avoid.

1 Like

You are looking for some sort of “GetClassByName” function.
Take a look at this post.

https://answers.unrealengine.com/questions/246141/how-to-get-class-by-its-name.html

However, when you have the names already as strings, then you can just loop through all your media players (all actors of class) and assign the media references there.

Hmm, that’s not exactly it unfortunately. That seems to be a way to get a particular class by it’s name, unless I’m misunderstanding it. What I want is to get hold of a particular asset of a class by it’s name.

Essentially, let’s say I have a folder in my content called ‘Materials’ containing a whole load of materials:

Material_Tex_Mat_001
Material_Tex_Mat_002
Material_Tex_Mat_003
Material_Tex_Mat_004
Material_Tex_Mat_005
etc.

What I want is a Blueprint node that I can enter the string name for one of these materials (eg. ‘Material_Tex_Mat_03’) and get the actual material reference returned.

Note that these materials do not exist in the level as actors, they are simply materials in the content of the project.

I’m now exploring this in C++ (which I’m pretty rubbish at to be honest), but keep crashing the editor. Here is my post on AnswerHub: https://answers.unrealengine.com/questions/380268/crash-trying-to-get-material-reference-cbp.html

I feel like this shouldn’t be a very hard thing to do (get an asset with the string name, and perhaps filepath) but can’t figure it out.

If I’m understanding correctly what you want to do, you can make a csv file with 2 values, the first being Name and the second being Material. The first column would be the name of the material, and the 2nd would be the actual path to it, for example, something like:

Name,Material
Red,“Material’/Game/Materials/RedMaterial’”
Blue,“Material’/Game/Materials/BlueMaterial’”

and then in Unreal, make a struct that has 1 variable, type of Material.
Then drag the csv file into unreal and when it asks for the struct type choose the struct you created.

Then in your bp, when you want to access that material, you right click and use a node called Get Data Table Row, and click the Select Asset and choose the name of the csv file you imported, and in the row name, pass in the name of the row that had the material. You should be able to break the out row and get your material that way.

2 Likes

Ispheria: YES! That’s it! ****, seems so obvious when you know how.

I can finally stop poking around inside C++ trying to make custom nodes for something that already exists. THANK YOU.