How to get material instance to show in class defaults?

I’m trying to pass a material instance to another actor through the use of class defaults. I found a way to make this work by setting the object type of the material variable to AssetID. But the problem is that sometimes it doesn’t load the asset properly. I have no clue why as I don’t really understand how assetID’s work. I found little to no information on the subject, yet I gave it a try nonetheless and it seemed to be exposed as a class default and 70% of the time it actually works. But sometimes, for example after restarting the editor the assetID would not load.

Can someone explain how assetID’s work? And how I can pass a material instance as class default?

Why AssetID and not Material Reference?

Because material reference doesn’t show when getting class defaults. I guess the reason for that is because it’s a direct reference to an object that doesn’t really exist, hence why it’s not exposed as class default.

I did find a way to make it work. I wasn’t loading the assets, I was just reading the assetID and resolving them into a reference. But as the resolver states, when the asset isn’t loaded this resolve returns null. Which also explains why it worked around 70% of the time. Sometimes the assets would be loaded somewhow, sometimes (after editor restart) they wouldn’t. So I used a load asset node in the origin object and now it works. However, I’m still wondering if there is a method that doesn’t involve assetID’s?

Hmm, Ok basically the problem I have with the load asset thing is that I’m loading the asset in the source object. Which is an inventory item. When the actual item is spawned in the world the material instance asset is loaded into memory. Which all works fine. But there is a problem. Imagine a rare inventory item, an item that spawn only once per week for example on a server. A lucky player found this item and equiped it. Server goes down for maintenance, server comes back up. Item is no longer part of the world, hasn’t respawned yet. Lucky player re-connects. Oops, his item isn’t loaded. Why because the item is loaded in the source object, which isn’t part of the world anymore / yet.

Possible solution could be, loading the asset inside of the player when he equips it. But that would mean every item the player equips gets loaded, does this mean that when the player equips similar items who share the same asset get re-loaded into memory everythime he equips it? Or does asset loading work in a way that a particular asset can’t be loaded twice, once it’s loaded, it’s loaded? Or does it actually load it again? These are questions I need answers to, because this is a big deal when it comes to optimization. Loading assets isn’t exactly something I want to have happen every second.

Ok, I found a way. The resolver returns none when the asset isn’t loaded, as such, when it is indeed null, I load the asset. This way the asset only gets loaded when it isn’t already.