Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by casimps1 · Mar 04, 2013 at 10:21 PM · prefabassetbundledependencies

How do you properly load Asset Bundles with dependencies?

I've read the Unity docs about Asset Bundle dependencies and seen several examples of using Push/PopAssetDependencies when building the bundles. However, I have yet to find any examples of actually loading these dependent bundles at runtime. Can someone show me how that should be done?

So, for example, say I have multiple character prefabs that all share the same huge skin texture. And let's say I want to make each prefab its own bundle. Then, ideally, I want each prefab bundle to be dependent on a separate skin texture bundle. I know I need to load the texture bundle first. But does just calling Load on the texture bundle magically make the reference when the prefab bundle is loaded?

Comment
Add comment · Show 2
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 smartkiran · Apr 05, 2013 at 07:56 PM 0
Share

Did you find a solution to this ?

avatar image Iamdain · Jan 13, 2016 at 10:30 AM 0
Share

How do you make the character prefab bundle/s without including the texture? Do you code it explicitly not to include that dependency or something like that?

2 Replies

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

Answer by casimps1 · Apr 09, 2013 at 03:40 PM

Answering my own question here. Yes, it more or less happens magically, which is nice. Here's a simplified version of the code I used:

 // Load the dependency bundle required by the prefab bundle
 // This contains things like Textures that wouldn't be instantiated separately
 WWW www = WWW.LoadFromCacheOrDownload( depBundleURL, depBundleVersion );
 yield return www;
 www.assetBundle.LoadAll( );

 // Load the prefab bundle containing references to assets in the dependency bundle
 // This bundle contains things like prefabs that will actually be instantiated
 www = WWW.LoadFromCacheOrDownload( prefabBundleURL, prefabBundleVersion );
 yield return www;
 GameObject prefab = www.assetBundle.Load( prefabName );
 

That's it. The first LoadAll call loads all the dependency assets into memory but apparently you don't need to store references to them or anything. I assume they are referenced later by GUID or something because loading the prefab and instantiating it just works with no extra effort. And it's always a welcome surprise when Unity just works!

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 cory_munky · Feb 17, 2015 at 08:17 PM 1
Share

If you www.assetBundle.Unload(false) on the first bundle, will the second bundle still find it's asset references that were loaded by the LoadAll()? Or, do you have to have both bundles' file data in memory simultaneously for dependencies to be resolved?

avatar image NoseKills · Oct 05, 2017 at 07:38 AM 0
Share

In my experience you don't need to call dependencyWww.assetBundle.LoadAll( );.

Just accessing the www.assetBundle getter is enough to make dependencies work, which I think is a pretty confusing API decision.

Basically you need to do

 WWW www = WWW.LoadFromCacheOrDownload( depBundleURL, depBundleVersion );
  yield return www;
  var temp = www.assetBundle;

which is not intuitive at all. The .assetBundle getter is a getter and an intialisation method combined.

avatar image FaiyazOfficial · Sep 26, 2018 at 11:57 AM 0
Share

how to secure assest bundles from being used into other apps?

avatar image
0

Answer by NestorAlgieri · Sep 26, 2018 at 04:41 AM

They should have called it www.LoadAssetBundleHead() because it is putting the asset bundle header into memory. Basically once the header is in memory Unity will know to go load stuff from that bundle when needed, be it explicit load calls or dependencies.

e.g.

AssetBundle-A contains materialA AssetBundle-B contains a prefab-A that uses materialA

When you called www.assetBundle for the loading of AssetBundle-A it will load this bundle's header into memory. This bundle's header has information that is holds MaterialA.

Now when you load AssetBundleB using the same method, then you explicitly load prefab-A from AssetBundleB, unity knows that prefab-A has a dependency of MaterialA in AssetBundleA, so it will go and load MaterialA from AssetBundleA automatically for you.

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

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to build asset bundle without dependencies? 1 Answer

Script causing prefab export to have HUGE dependencies? 1 Answer

Prefabs and new asset bundles system 0 Answers

Asset Bundles and Scripts 1 Answer

Can I use Prefabs instead of Scenes for AssetBundles? 1 Answer


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