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
0
Question by ChristopherDrum · Oct 08, 2013 at 09:17 AM · assetbundleloading fileexternal assetsasset path

Is there a unified method for loading assets?

We need the app size to be below 50MB when the user downloads it for the first time (mobile app, from the App Store), and then we load the rest of the resources from our private server.

My understanding is that this will put our resources into two different locations, and therefore the loading mechanism is a little different for each.

As I understand Unity3D, at this stage of my studies, there are two primary ways to load assets in Unity:

  • WWW.LoadFromCacheOrDownload()

  • AssetBundle.Load()

My understanding is that I would use AssetBundle.Load() for those assets that are included in the application binary package. If there is an asset bundle, perhaps with a new game level and creatures, then I could grab that (say from a server) via LoadFromCacheOrDownload().

Subsequently, resources can become split into two piles:

  • Assets > Resources folder

  • the local cache

The result of this seems to be that the loading mechanism is dependent upon where the resource lives physically on the disk. This strikes me as a little bit strange: a resource is a resource, just load the darn thing.

As such, it seems to me that every time I load a resource, perhaps as dictated by a server-side XML file with a level construction recipe, I have to check every resource for existence in both places. It might be a static file, it might have been dynamically downloaded and cached, and it may not be known at compile time what combination of things will be combined and displayed to the player.

I want to be able to build scripts that don't have to worry about this level of detail. I just want to load the resource if it is exists, no matter where it exists, and use it.

Is my understanding of this situation accurate? If so, is there a standard Unity call that achieves what I'm looking for? Perhaps my thinking about the entire matter is topsy-turvy. If so, please feel free to call me out on it or question my assumptions.

Thank you.

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
0
Best Answer

Answer by dorpeleg · Oct 08, 2013 at 12:34 PM

You got it a bit wrong.

WWW.LoadFromCacheOrDownload() and AssetBundle.Load() are used together.

LoadFromCacheOrDownload works like so:

Check to see if the requested file (by URL and version) is already cached (saved locally).

If it is, load it from there (AssetBundle = download).

If it is not, download it from the URL (AssetBundle = download when download completes).

After the LoadFromCacheOrDownload is done (either from cache or from URL) you use AssetBundle.Load() to load object from the bundle to where you want.

For example:

 GameObject go = AssetBundle.Load("something");

I hope I explained everything you wanted.

Comment
Add comment · Show 11 · 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 ChristopherDrum · Oct 09, 2013 at 01:24 AM 0
Share

I see. Does this mean that in the case of multiple asset bundles, some of which were embedded in the initial app and some of which were downloaded and cached, that I have to always check both the Resources and the Cache every time, to find a requested resource?

Asset bundle A is embedded in the app and has a prefab and sound effect. Asset bundle B is downloaded and contains a new prefab (say, a new sword).

How do you handle game object instantiations of prefabs in a consistent manner when the resources themselves are now scattered? Calling objects probably don't know, nor even care, about where a resource lives.

avatar image dorpeleg · Oct 09, 2013 at 07:05 AM 0
Share

If you have stuff embedded into the app, you don't need to use asset bundles and LoadFromCacheOrDownload.

For stuff that are embedded (included in build) use: Resources.Load().

$$anonymous$$eep in $$anonymous$$d that in order to use Resources.Load you have to put your assets in a "Resources" folder in the project.

How do you handle game object instantiations of prefabs in a consistent manner when the resources themselves are now scattered? Calling objects probably don't know, nor even care, about where a resource lives.

You should think about it more.

Do you really need assets to be on a remote server?

Do you really need assets to be included in the app?

Are there same type of assets on both server and app?

In other words, think about the best way to keep things organised.

I might be able to give you more tips of you can share more info.

avatar image ChristopherDrum · Oct 09, 2013 at 07:29 AM 0
Share

Thank you for your continuing help. To answer your questions directly:

  1. Yes, I do need assets to be on a remote server. It is an absolute requirement for the project.

  2. Yes, I do need initial assets for the game tutorial to be included in the app at first download. This is also a requirement from management.

  3. When you say the "same type", do you mean "type" as in "textures"? If so, then yes, some textures might come in a future asset bundle download from the server, as new enemies are released for special events. So, imagine a level where the player fights monsters. The basic monsters in a newly-downloaded level remain the same as always, just basic grunts to kill, and the boss is a special monster that came with the new asset bundle.

avatar image dorpeleg · Oct 09, 2013 at 09:00 AM 0
Share

Ok, so you should try and write your code is such a way that it will know when it needs to download from web and when it doesn't.

I don't think it will be very complicated.

So in your example, you load all basic grunts using Resources.Load and load the boss using LoadFromCacheOrDownload.

If the level and the boss always go together, you can put them both in the same asset bundle.

avatar image ChristopherDrum · Oct 09, 2013 at 09:20 AM 0
Share

That basically gets at the heart of the matter. So in that example the grunts have one loading mechanism and the boss has another. This means that before loading, we need to know where the resource is.

Let us assume that a generic script is responsible for assembling the level. That script doesn't necessarily know which resource comes from which asset, especially for future asset bundle releases.

It sounds like some kind of Resource $$anonymous$$anager needs to keep track of which resource lives where? Then, the generic level building script would not call Resources.Load directly, but rather a hypothetical "Resource$$anonymous$$anager.Load" function. The $$anonymous$$anager would decide whether to use Resources.Load or LoadFromCacheOrDownload, depending on the situation.

Do I have this straight? Does Unity already have such a function?

Show more comments

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

16 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 avatar image

Related Questions

I want to build in the resources folder, except for 0 Answers

Find all assetbundles in folder 0 Answers

Load A complete unity game using other program 2 Answers

Loading Assetbundle scriptableobject settings. I can load the Scriptableobjects and place them in a list just fine but variables that are apart of it don't load. 1 Answer

How to load external assets WITHOUT 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