How to get an AssetID in Blueprints?

Hi all, I have a question – how do you actually GET the Asset ID’s you would want to potentially load? I can’t find any documentation on this, except https://answers.unrealengine.com/questions/300392/why-does-a-functions-local-variable-of-type-asseti.html

I simply need to know how (in blueprints) to get the value of an AssetID for a static mesh in my project. Can anyone tell me how I can do this? It seems you cannot produce any Input for the LoadAsset function without C++.

thanks, Never

The answer is that you don’t get Asset ID’s because they don’t exist as a property of static meshes or any other objects. The best you can get is the name of the asset (use GetDisplayName() or GetObjectName()) – these are given to all UObjects, which everything within UE4 inherits from.

In the link you provided, the other person created a data table with a column named “AssetID” and they’re trying to use it as an indexed lookup value to fetch rows, similar to how a SELECT query would work within SQL.

Ok maybe Asset ID is the wrong way to go. To be clear, what I want to do is to populate a static list or array with some of the meshes that exist in my project (whether it’s Asset ID’s, File paths, etc, whatever). We’ll call them ‘ships’. I want to be able to cycle through that list of ships and dynamically Load them into a Static Mesh component I have in my Pawn blueprint.

I would fire something like this Set Ship Mesh event when I wanted to change the ship for my pawn:

I am simply trying to figure out how to dynamically load meshes, based on some static list of possible meshes in my project. Is it possible to create such a list of assets to load (in blueprints)? If yes, and that list is not of type AssetID, what type should it be? and how do I perform a Load Asset (or similar function) on them? I am not working with a database. All i know is that I have a bunch of meshes in my project that could potentially represent my pawn, and I need a way to cycle through them… I just don’t want to load them all if I don’t have to.

thanks,
Never

Howdy!

As Slayemin pointed out, GetDisplayName or GetObjectName is the way to go. GetObjectName, will return the “unique id” for the object, as well as GetDisplayName (if you pick the correct one, there are two nodes available). I have always seen GetObjectName be unique, no matter what I did to the Blueprint, from setting the “Object Class”, to whatever. Some of the options for setting up a blueprint, change things, but GetObjectName always seems to be unique.

To use what you get back, is a much larger discussion, it will depend on many things, what are you getting back/looking for, etc (yes I know what is here in the post, but what else?). Assumng static meshes, the nodes are going to return a string, as most nodes in UE4 do. So when you are trying to Spawn a Actor, or a Add a Primitive Component, that “string” is going to need to be set to a variable (or you could use it directly out of an array of course, if that is where you are keeping them using a Get node, once you have found it in the array, and have it’s index)

Then depending on what it is, again spawn an actor, or add a component, well the “string” variable is going to be used after the Add Static Mesh Node, when you use the Set Mesh Node. And it will proceed in that fashion, depending on what you are creating, etc.

I have not written anything exhaustive, because to be honest, that would be a book! lol

Hopefully this is enough to get you started.

Have a great day!

Oh, this is actually VERY easy. Just create an array of static meshes within your blueprints local variables. Populate that list with all possible static meshes you’d like to load (within the editor). You can use the array index as your “asset ID”. To load a static mesh at runtime, you’d just access an array item by array index from the static mesh array and then set the static mesh to the retrieved item.

Slayemin, thanks, your suggestion will switch my static mesh but unfortunately the mesh is getting instantiated when I populate the array of possible mesh references. Here is my example – I have a custom PlayerController that stores my arrary of possible mesh references that it’s pawn could be. For simplicity’s sake, when play begins, I add two arbitrary Static Meshes to my default (custom) playerController’s array:

And I have a custom Pawn class that is possessed by my PlayerController, in this class I created an event to set the Static Mesh component called ‘ship’ in my Pawn:

So I have add two references to the array of Static Mesh references, in my custom PlayerController. I have a function that will set the mesh component in my pawn a a given Static Mesh. Now in a UMG, i want to be able to cycle through the meshes in my array, setting the component (‘Ship’) in my pawn to a Loaded mesh reference:

Again this is for simplicity’s sake – one button just sets the ‘Ship’ static mesh component in the Pawn to the mesh at index 0, and the other umg button sets the Ship to the mesh at index 1.

This works. It switches the ship when i click the button. However, I have to think that both meshes were loaded when i added them to the array in my PlayerController BeginPlay event (the first screenshot). Am I correct in saying that this will essentially load the meshes on Being Play, because that’s when they were added to the array?

Sorry I am still trying to grasp some pretty basic concepts about blueprinting, coming from a c++ (standard library) background. :slight_smile:

, thanks for your answer. Still don’t understand how the strings (i.e. object name) can be used to dynamically load a static mesh though. Maybe I’m dense. Will keep at it :slight_smile:

Thanks!

Yes, I am dense. It just occurred to me that I can manage the load state of my asset list independently. will post an update when i get it working. thanks again

Ok, I found you can accomplish dynamic loading of a static list of assets by building an array of strings/bools that represent the assets you would possibly load, and a t/f for whether they are loaded. Before you set your static mesh component, check the bool array to see if it has been added to the reference array… Here’s my custom playercontroller (note the array variables… a static mesh reference array, a string array, and a bool array). This is how i ‘build my list of possible assets to load’:

My custom pawn class simply contains a function to set it’s main Static Mesh component (called ‘Ship’) to a new mesh:

No assets have been loaded at this point, just a couple arrays in my custom PlayerController.

Now here’s the dynamic part – below is an example of one button click handler in a UMG i have – this is for demonstration purposes only (it will always try to load the same asset). This will check the bool array to see if the asset with the name ‘ship1’ has been loaded. If not it adds ‘ship1’ to the static mesh reference array, then sets the component to the new reference. If it has been loaded already, it just sets the component to the existing reference in the array:

I think this is doing what I want it to, but i’m not sure how to confirm. Because i am adding the reference to ‘ship1’ to the array inside this button event handler – does that make it dynamic? i.e. is ‘ship1’ actually loaded when it is added to the reference array? Or is UE4 ‘too smart’, and sees that it could possibly hit that branch of code, and so pre-emptively loads ‘ship1’?

hopefully that makes sense. At this point I would just like to hear confirmation that what I am doing is actually a dynamic load.

thanks again!

Never

Uhm… well, I would say almost all of this is unnecessary. This is something I would consider to be a premature optimization to solve a problem you don’t actually have. You’re not going to run into any performance issues even if you had every static mesh in your game loaded into memory. Let the game engine worry about the most optimal way to load static meshes from its content library – you’re over thinking this and probably reinventing the wheel.

Just store the static meshes you want to use in an array, then call them when you need to use them. It’s the fastest and simplest solution :wink:

Thanks again for the reply. I tend to overcompliate things when I don’t need to, yes I am sure you are right about that. hah. But I am not looking for the fastest/simplest solution. I am looking for the absolute correct solution – one where I have control over what’s loaded when :slight_smile: (and yes, i know the tripple array thing is sloppy at best, I just wanted to get it right, conceptually)

Can you explain WHY i should “let the game engine worry about the most optimal way to load static meshes from its content library” ? Theoretically, say I have 400 high poly models that use multiple 4k textures each, I don’t want to load ALL 400 of them (with textures) into memory, especially when the user will only ever look at 3 or 4 of them. In that case, WHY is it okay to add them all to a static mesh reference array before any of them are known to be used? As a c++ programmer i want to have utter control over when things are loaded and destroyed (but am challenging myself to do it all in blueprints) :slight_smile: If nothing else, I at least need to understand why it is ok to just let the engine manage it.

thanks again!

Never

Before using UE4, I built my own homebrew game engine and had to worry about loading assets into memory from disk. I had come up with a somewhat complicated system, where my asset library would store the asset into a hash table by a unique asset name and the file path to that asset on disk. If someone requested the asset and it wasn’t loaded, I’d load the asset and then stream it in, on an ‘on demand’ basis. The loaded asset would be stored as a static variable, so it would only get loaded once. The user of my engine didn’t have to care about asset management, all they had to do was add the asset to the engine and use it whenever they needed it. The engine would do the rest to make sure that it’s not loading assets it doesn’t need. It was a decent asset management system.

Now, UE4 is a pretty advanced engine. Probably one of the best. I haven’t bothered to dig deep into their asset management system, but I would imagine that they use a similar scheme, but a lot more advanced. If you pay close attention, the engine will actually do its best to stream assets into your game as quickly as possible to fill the scene first, then it makes the scene look pretty. The initial assets will be at a much lower level of detail, but when there’s extra CPU time to process those assets, it will increase the LOD as needed. So, if you have 400 high poly models, the engine will do its best to make them easily accessible while also being frugal on memory usage (unverified claim, I haven’t looked at that particular engine source code). I also suspect that they use lazy initialization pointers for assets (maybe with reference counting as well?), to get the ‘on demand, only as needed’ usage.

it looks like this question gone to another subject. In my tests AssetIDs proved to be very important to reference actors that are on another sublevel because it stores the path of an unloaded instance. That’s really good.

but there is no “Get Actor Asset ID” node making it unusable because you can only pick manually.

Is there any plans to implement that?

This is an old question, but it’s one that’s still relevant for many people, so here goes…
Asset IDs, AFAIK, haven’t been exposed much to blueprints. However, it’s been in the C++ world for a while now, so with a little bit of coding knowledge, one could easily extend it’s functionality into blueprints.

The main thing to look at is the Asset Manager.

You can also look at this post by Ben Zeigler, who was kind enough to attach a PDF document explaining the process in detail.