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
14
Question by PolC · Oct 31, 2009 at 10:51 AM · asset

Dynamic Asset loading?

Is is possible to load assets (models/textures/sounds) on runtime?

Been peeking the forums and saw some old posts where it wasn't but then i saw Resource.load, so i'm confused.

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

6 Replies

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

Answer by DannyL · Oct 31, 2009 at 08:44 PM

Yes, this is possible - check out the AssetBundle class (http://unity3d.com/support/documentation/ScriptReference/AssetBundle.html). This class is for loaded via the web specifically, I assume this is what you had in mind? Resource.Load() is used for loading assets by path name in the resources folder.

AssetBundle has been introduced fairly recently, hence the old forum posts where this was not possible.

Comment
Add comment · Show 2 · 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 BerggreenDK · Jun 19, 2011 at 10:50 PM 0
Share

its an Unity PRO only thing, right?

avatar image VonTalavang · Mar 19, 2012 at 01:26 AM 1
Share

no matter how many times i read that...

i still cant do it

avatar image
9

Answer by baha · Apr 24, 2010 at 08:55 AM

hi, actually when using the resources folder the asset is encapsulated within the unity file (as part of it) this means that it is not fully dynamically loaded thus if you want to load a file that is not in the resources folder then you need to rebuild your application after adding it to the resources folder, resources folder is always attached and deployed with the unity file but if you want really dynamic loading of assets you need to use the WWW Class either you pick asset bundles for your content streaming (Pro) or you might use its functions to load Textures, Audio, Video and to load models you mights take a look at Mesh Serializer2 at unifycommunity.com.

resources folder will always combine your files and assets within the unity file thus you can't load them unless they are built within the unity file, other content deployed somewhere else can't be loaded through Resources.Load() function.

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

Answer by Pixelstudio · Nov 14, 2009 at 11:53 AM

yes it is very simple. All you resources got into the directory "resources". Then you can use resources.load to load them into you scene at runtime.

Comment
Add comment · Show 1 · 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 Lenn Dolling · Jan 17, 2012 at 10:29 AM 0
Share

yes.. very simple. if yo don't have the directory/folder "resources" in your assets folder then you should make it and put all your prefabs in there. I found it golden.

avatar image
1

Answer by kilgore · Jun 06, 2010 at 02:05 AM

I just recently ran into the same issue and wanted to post the following code, it is basically an extenstion of what xeophin posted and I can confirm that it is working.

In this example, I have a GameObject with an AudioSource component attached and a script with a function called PlayClip. I pass the audio clips name that then loads clip from the Resources fold.

public void PlayClip(string clipName){
     AudioSource source = gameObject.GetComponent<AudioSource>();
     source.rolloffFactor = 0;
     AudioClip clip = Resources.Load(clipName)as AudioClip;
     source.clip = clip;
     audioSource.Play();
 }

note - I am making the AudioSource rolloffFactor 0 so that it can be heard everywhere without, well, fallOff. That one got me for a few minutes.

Comment
Add comment · Show 2 · 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 Tetrad · Jun 06, 2010 at 02:59 AM 1
Share

It's important to note two things about the Resources class. 1) Filenames passed in should not use extensions. 2) Everything in your Resources folder is loaded at run time and not on demand. It doesn't actually stream it in or block to load the file.

avatar image guavaman · Oct 06, 2012 at 06:45 AM 3
Share

2) Everything in your Resources folder is loaded at run time and not on demand

This is not true. Everything in your resources folder is included in the final game build whether used or not, but the contents are not loaded into memory at runtime. Objects will only be loaded into memory if they're referenced in the scene or Resources.Load() is called on them. That's the whole point of the class. Resources.UnloadAssets() and Resources.UnloadUnusedAssets() exist so you can reclaim memory used by dynamically loaded assets if needed. You can always reload them again with another Resources.Load() call.

Just to make sure, I built two test exe's from my game, one with all my current stuff in Resources, and one where I moved about 300$$anonymous$$B of ogg and dds files out of Resources. None of these files are loaded in the scene. Both exe's take up the same 518$$anonymous$$B of memory when run, which shows that 300$$anonymous$$B of data I moved out of Resources was not being loaded at runtime. (Thank goodness, I was worried you might be right and I had been misusing Resources for almost 3 years.)

avatar image
0

Answer by xeophin · May 25, 2010 at 06:45 PM

Sorry just seconds after I posted the comment, I got it to work, using the following code (assuming the same example you used):

AudioClip clipObj = Resources.Load("GoodAfternoon") as AudioClip;

That should work.

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
  • 1
  • 2
  • ›

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

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How I can get an instace of a material, created in a project panel 1 Answer

Asset Managing for Mobile Devices 0 Answers

Setting Scroll View Width GUILayout 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 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