Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DrummerB · May 27, 2017 at 02:30 PM · editorassetsasset storeresourcesassetdatabase

How to load an asset without a reference?

I implemented a basic editor extension to help me with some of the workflows of my project. I needed this extension to be loaded without any user interaction, i.e. no custom prefabs or scripts in the scene and no EditorWindow. To achieve this I annotated a class with InitializeOnLoad and subscribed to some editor events.

This works pretty well, but now I need to render some small sprites on the scene view and I'm having trouble accessing the textures to do that. Since I'm not using a MonoBehaviour or ScriptableObject for this extension, I probably can't set up a reference to those assets anywhere.

I could load them from a hard coded path using AssetDatabase.LoadAssetAtPath, but that doesn't seem to be a good idea either. If I were to ever release this asset, the user couldn't move it anywhere from the hard coded path.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Bill9009 · May 29, 2017 at 07:13 AM

Would the user need to move it from the hard coded path?

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DrummerB · May 29, 2017 at 10:00 AM 0
Share

Some people like to move all their downloaded assets to an "External" or "ThirdParty" folder. So I'm wondering how published assets can load their own resources without breaking when the user moves everything to a different folder.

avatar image Bill9009 DrummerB · May 30, 2017 at 04:08 AM 0
Share

You could directly use the GUID's to find the assets. As long as the Assets are in the Assets folder you can use:

 AssetDatabase.LoadAssetAtPath<T>(AssetDatabase.GUIDToAssetPath("GUID Here"))

To get the GUID open the .meta file associated with the file being opened. This will only work in the editor however.

avatar image DrummerB Bill9009 · May 30, 2017 at 12:57 PM 0
Share

Wouldn't the GUID be different for every user? I believe the GUID is generated during import. So I would have to find the asset first to get the GUID, but that's what I'm having trouble with.

avatar image
0

Answer by PizzaPie · May 29, 2017 at 10:40 AM

I am using something like this ->

 string[] guids =  AssetDatabase.FindAssets("t:MyClassType");    //see the docs for the tags (t:) means looking for type
         if (guids.Length == 0)
             return;
 
         for(int i = 0; i < guids.Length; i++)
         {
             string path = AssetDatabase.GUIDToAssetPath(guids[i]);
             list.Add((MyClassType)AssetDatabase.LoadAssetAtPath(path, typeof(MyClassType)));          //list typeof MyClassType
         }

That finds reference/loads all assets typeof MyClassType.Probably there are other ways too. Cheers.

Edit: We are talking about editor time and not runtime, right?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Error using ImportAssetOptions.ForceSynchronousImport 2 Answers

Unity recompilation time slowly increases each time it's recompiled. Why? 0 Answers

Loading subassets at runtime 1 Answer

How do I import assets from the Asset Store while offline? 2 Answers

AssetGraph bug fixed request(Override Import Setting doesn't work) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges