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 psdev · Jul 05, 2011 at 06:08 AM · materialstexturesresourcesdependencies

Does loading a Resource load that resource's dependencies?

If I load a resource, say a Material using Resources.Load() - does that Material's dependencies, such as its normal map texure, get loaded automatically? Or do I also have to manually do a Resources.Load() on the texture used by that loaded Material. And if so, does the loading order matter?

Also, related (this isn't really a separate question): If I'm using Resources.Load() then all loaded assets need to be duplicated into that Resources folder - right?

I mean I've read the docs on Resources.LoadAssetAtPath() but it says it only works in the Editor. So that means I have to use Resources.Load() and that if I have my project organized so all my Materials are in /Materials/ folder and textures in /Images/ folder then that means if I want to load them at runtime, then I have to make a duplicate of them into the Resources folder too? Is that right? Am I crazy in my thinking or is that a bit goofy since I'd now have to keep the 2 materials and 2 images in sync throughout my project folder?

Thanks for any clarification on Resources and Resource dependencies.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Waz · Jul 05, 2011 at 06:36 AM

A build (for WebPlayer, EXE, etc.) is composed of all Resources, all Scenes that are listed in the build settings, and all their dependencies.

When you "load" a resources, all you are doing is finding the reference to it given its path. Similar, if Level0 has a Foo in the hierarchy and that Foo has a script variable set to a Gumby prefab and that Gumby has a renderer that uses material Baz and that Baz material uses the Jello texture, all these assets of the project are included in the build.

Resources are just the same, except they (and all their dependencies) are automatically included in the build (actually along with Level 0 by default).

Personally, I would prefer this:

 var availableDogSkins : Material[];
 ...
 dog.renderer.material = availableDogSkins[choice];

to this:

 dog.material = Resources.Load("DogSkin"+choice) as Material;

As you can see, there is no way Unity can work out that DogSkin1, DogSkin2, etc. materials need to be included, those are "hidden dependencies", and hence you'd have to use resources. Whereas in the former code, it only needs to include those materials which you drag to the availableDogSkins array, and it knows those explicitly from your hierarchy.

And yes, it's goofy and crazy thinking to duplicate assets unnecessarily!

Comment
Add comment · Show 5 · 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 psdev · Jul 06, 2011 at 11:21 PM 0
Share

Thank you for your detailed answer. :)

Can you please also confirm that if my scene does not have an object in the hierarchy which refers to say, an alternate t-shirt material, and assu$$anonymous$$g I want to dynamically load new t-shirts in game, then I have to copy all my t-shirt materials from their natural place in the folder structure in the project where I have them, into the Resources folder in order to be able to use them in-game with Resources.Load()? I can't tell from your response if you are saying I am goofy for thinking about duplicating resources, or if Unity is goofy for making you duplicate them. ;)

And can you please clarify what is the point of Resources.LoadAssetAtPath() if you can't load a resource from some specific folder within your project?

avatar image Waz · Jul 07, 2011 at 12:34 AM 0
Share

I think you're under a misassumption about what "dynamically loading new t-shirts" might mean. Unless you are using AssetBundles, the only objects you can "load" in any sense are those built into your project, as deter$$anonymous$$ed by the dependencies as I have explained them. Listing a prefab (my availableDogSikns) versus loading a Resource are practically the same thing. If you can clarify what differences you are imagining, we can help.

Specifically LoadAssetAtPath only works in the Editor. It's not for runtime use.

avatar image psdev · Jul 07, 2011 at 04:35 AM 0
Share

sorry, I'm sure I have Unity ter$$anonymous$$ology wrong. I'm trying to equate this to Flash and the "library" in Flash where anything in the library can be instantiated on the stage at runtime.

So say my Unity Project has 1 scene, with 1 FBX in the game scene Hierachy (on the stage whatever it is called) and that FBX has a Tshirt1 material on it. If at runtime I want to put Tshirt2 material on it and that material is nowhere in the stage/game hierarchy but is in the project, then I use Resources.Load(). And that material needs to be wherever it is normally in the project PLUS being in the Resources folder.

Is my mistake equating the Unity Project panel to the Flash library? $$anonymous$$y understanding is that Flash doesn't include assets in the library into the build if it is not used or referenced in code when it is compiled. I assumed Unity does the same? Or is the Unity Project more of a collection of available files you can use in your project- more akin to a Visual Studio solution or something?

I should read up on asset bundles but I thought they were used for over the internet updating of content or in app purchases? Thanks, I do appreciate your clarification. :)

avatar image Waz · Jul 07, 2011 at 09:33 AM 0
Share

Certainly don't duplicate assets in multiple places. That I'd definitely wrong and unnecessary. Resources can be used as a library concept, but it is just as correct to put the whole "library" of prefabs into an array of references to the assets, in the hierarchy.

avatar image psdev · Jul 11, 2011 at 05:47 AM 0
Share

thanks for your help!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Editor doesn't load (some) dependencies with the scene, but standalone does? O_o 1 Answer

Skinned Mesh Renderer Material 1 Answer

Setting a material texture and saving it 1 Answer

map of earth on material (sphere) is distored - Why? 0 Answers

Draw call increased on duplicated object. But not on others 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