Unity UIToolkit - AssetDatabase.LoadAssetAtPath vs Resources.Load

are there a specific reason why he use AssetDatabase.LoadAssetAtPath over Resources.Load?

Hi @Kasperfly, great question.
While you could use Resources.Load(), this requires your files to be in a Resources folder to work.
It’s generally best practice to avoid this approach and Unity themselves now recommend using addressables instead. However, that process is a bit too involved for this short course so I took the simple approach of using AssetDatabase.LoadAssetAtPath() instead.

If you prefer a different approach then feel free to deviate from what I do in the course. There are many ways to skin a cat, as they say! :slight_smile:

don’t you run into problems when moving the editor folder when you use addressable?
I can only see a disadvantage so far, that you cannot move you editor a folder or am I completely wrong?

here is what I did.
EditorResources

In my implementation, you would need to update the path in the script if you decided to move the folder to another location. It’s probably the least flexible option available but it’s very simple and once you’ve set things up you probably wouldn’t have a reason to reorganize the file structure much anyway.

For Addressables, my understanding is that you access them via an asset reference, so you would be free to move them around in your folder structure and not break anything. I’ll be honest though, I’ve not really played with the addressables system yet so can only go by what I’ve read from the docs.

Regardless, the approach you inevitably take when writing an editor script can be somewhat arbitrary. Everything will have to live inside an editor folder and this gets removed from the final build when all is said and done. Any noticeable performance gains/losses from choosing one method over another would really only come into play for large projects, so I’d honestly tell you to pick whatever option you prefer/works best for your project.

So to my understanding there are no benefits for Addressables they are only downside vs Resources.
I’m just trying to understand why you would use Addressables over Resources when it comes with downside that Resources fix.

is it just the fact that you didn’t know or did you choose it for a specific reason?
the code different is really small.

sorry if I seemed a little persistent on this.

Adressables and resources are completely different.

Lets say you want to include a wide range of assets in your game, but you don’t want to have your initial installation to be bloated to infinity. Addressables is Unity’s solution to that. You can download an addressable from virtually anywhere, like a website or cloud storage after the fact. Or have a level that can only be gained as a reward etc. or changed on the fly.

You cannot do that with resources.

In mobile gaming, it’s important to have a small initial download otherwise people abort your game. Addressables are an important tool to help you pack more into your game without the need for the initial bloat.

They both have their place.

Unity has done some videos going through the benefits of Addressables. Go take a watch if you want to learn more about them.

In my own implementations, I do use Resources, but that is mostly because this is the system we use for managing inventory items in the RPG courses (of which I’m the TA), and as I’m already using them anyways, the extra bit of UXML isn’t really going to hurt much.

For the purposes of our Task Manager, if the script is in an Editor folder, you can put a Resources folder under it, and the system will work in the Editor, and not pack the Resources along with the final build. Just be aware that any script that is not in an Editor folder, even using #if UNITY_EDITOR cannot load anything from a Resources script in under an Editor folder… even in the Editor outside of play mode. This is a Unity limitation. (I learned this the hard way when rewriting my InventoryItemEditor).

If you’re writing a Runtime UIElement, I would avoid using Resources, and instead reference the correct UXML files through serialized fields.

@MichaelP and @Brian_Trotter Thanks a lot for the information.
I did not know that you could use Adressables to download from API in runTime very useful information.
I am aware that everything in the editor folder will not be part of the build anyway thanks for the info.

I watched some videos on the Adressables as @MichaelP suggests my own conclusion is that Adressables not the right tool for Editors except if you want to update The Editor from outside.

Thanks for your Time and help.

1 Like

You’re correct, Addressables are intended for runtime, not for things in the Editor domain. They are definitely something to explore for when it’s time to package your game, especially if it’s for Mobile.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms