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 PsychoDuckArcade · Jan 31, 2015 at 08:19 PM · editorassetassetsgeteditorscript

Editor Script: Getting all the models in a folder.

I want to make an editor script that will generate gameobject prefabs out of all models in a specified directory.

I got the menu GUI all setup, but I'm not sure how to do the logic. Specifically, cycling through all models in a directory (including child directories).

I'm guessing there's a method to get all assets in a directory, but I don't know hot to specify only models. I assume I could at least load all assets in a directory and then check if they have mesh renderer components. I just don't know what method that would be to get all assets in a directory, and haven't had any luck finding it.

Also what type of asset would model files be? (Imported .blend, .fbx, etc) I guess GameObject?

Comment
Add comment · Show 1
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 Nido · Jul 27, 2015 at 07:28 AM 0
Share

Waiting for the same answer.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Nido · Jul 28, 2015 at 09:49 AM

 string sAssetFolderPath = "Assets/Models";
         string[] aux = sAssetFolderPath.Split(new char[] { '/' });
         string onlyFolderPath = aux[0] + "/" + aux[1] + "/";
 
         string[] aFilePaths = Directory.GetFiles(onlyFolderPath);
 
         foreach (string sFilePath in aFilePaths)
         {
             if (Path.GetExtension(sFilePath) == ".FBX" || Path.GetExtension(sFilePath) == ".fbx")
             {
                 Debug.Log(Path.GetExtension(sFilePath));
 
                 Object objAsset = AssetDatabase.LoadAssetAtPath(sFilePath, typeof(Object));
 
                 //Here try something like INSTANTIATE(objAsset);
             }
         }

This returns you all models (specify extension in the IF statement). Then try to instantiate them or look for a "make prefab" solution in Editor. I'm waiting to know if this works, comment please ;)

Edit: The split in the path is because I was using this on a SelectedObject. But this version is modifyed for entire folder "Models" without selecting any object.

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 ruchirnaphade · Nov 09, 2020 at 10:09 AM

@PsychoDuckArcade ... I tried above code and I got the .fbx files from my folders. I want to make one fbx file child of another empty gameobject in my scene (Drag and drop functionality) but I am getting a below error:

Setting the parent of a transform which resides in a Prefab Asset is disabled to prevent data corruption (GameObject: 'Model').

Do you have any idea why it is like this?

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 Jeff-Kesselman · Nov 30, 2020 at 08:38 PM

You could create a file watcher in C# foir your given directory that runs asynchronously and calls you back, or sets a flag you can check in update if you need to do something on the update thread.

There are plenty of exampels for C# file watchers out there. Do a google.

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

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

Related Questions

ScriptableObject Asset corrupted after reload of Unity 1 Answer

Scriptable object meta info is hidden, where did it go? 1 Answer

Why Are My Project Assets Constantly Re-Importing? 2 Answers

Importing custom assets? 0 Answers

Trouble with asset store package not being reviewed 30days 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