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
4
Question by Ben 2 · Aug 03, 2010 at 08:01 PM · buildeditor-scriptingassetbundleassetbuildassetbundle

Can AssetDatabase.LoadAllAssetsAtPath Load All Assets Recursively?

I'm confused by the documentation for LoadAllAssetsAtPath. It reads:

*Returns an array of all asset objects at assetPath.

Some asset files may contain multiple objects (such as a Maya file which may contain multiple Meshes and GameObjects). All paths are relative to the project folder. Like: "Assets/MyTextures/hello.png"*

I know some assets contain multiple objects. Would a path such as:

"Assets/BunchOfStuff/"

load all the assets under BunchOfStuff recursively? It doesn't appear so. When I call:

AssetDatabase.LoadAllAssetsAtPath("Assets/SomeDirectory");

As a path that contains child assets, I get two Objects returned. It doesn't matter if there are more assets under that part or no assets at all. Always 2 are returned. I'm not sure what they are.

I'm trying to script an automated build for a bunch of asset bundles containing a large amount of content (text and images). I don't want to have to enumerate all the assets I want included in the case where every asset should be included. I've seen the simplified example scripts but I've not seen any yet that handle a bunch of assets.

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

Answer by matfrem · Mar 20, 2013 at 04:18 PM

You can just list all files usung file listing and load them one by one:

 string[] aMaterialFiles = Directory.GetFiles(Application.dataPath, "*.mat", SearchOption.AllDirectories);
 foreach(string matFile in aMaterialFiles)
 {
     string assetPath = "Assets" + matFile.Replace(Application.dataPath, "").Replace('\\', '/');
     Material sourceMat = (Material)AssetDatabase.LoadAssetAtPath(assetPath, typeof(Material));
             // .. do whatever you like
 }
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
0

Answer by zyzof · Sep 04, 2012 at 03:09 AM

AssetDatabase.LoadAllAssetsAtPath() only works if you specify the path of a single object. It will load all the assets that are children of that asset.

It sounds like you want to use Resources.LoadAll(path), which will load all the assets at the specified relative path inside any folder named "Resources" (you might have to rename/rearrange your project hierarchy)

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 wrxmarcus · Dec 21, 2012 at 06:13 AM 1
Share

Are you suggesting that our asset we would wish to make asset bundles with should be in the Resources directory? I don't want these assets in my Build... I guess I could create subdirs in resources for each thing i wanted to bundle. Ben 2 - how did you go about solving this? right now I'm looking into using c# to simply iterate through all the files in a folder I want to use for an assetBundle and then manually create a list of objects based on my list of files. thanks all!

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

When looping through assetbundle assetdatabase how do you reference a material object 0 Answers

Where are the built scripts stored in a build? 1 Answer

AssetBundles - depend on asset already included in executable 0 Answers

Distribute terrain in zones 3 Answers

Asset bundle mismatch in different Unity version 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