Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 BerggreenDK · Aug 08, 2011 at 09:00 PM · importeditor-scripting

Reimport a specific folder?

I think the subject line says it all.

But, is it possible to make an Editor script (callable through the Editor menus) where we call the Editor rightmouse command "Reimport" on a folder, but hardcode it to the folder "Resource/Models"?

Just wondering if this is possible?

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

Answer by Joshua · Aug 08, 2011 at 10:58 PM

This little script will import all the assets contained in the folder you currently have selected, and all it's sub-folders. Just save this script in a folder in your project called Editor. Next, go to Assets > Reimport Folder and it will reimport the folder you currently have selected.

 import System.IO;
 
 @MenuItem( "Assets/Reimport Folder" )
 
 static function ImportFolder()
 {
     var realPath : String = Application.dataPath;
     realPath = realPath.Remove( realPath.Length - 6 );    
     var selectedPath : String = realPath + AssetDatabase.GetAssetPath( Selection.activeObject );    
     var fileEntries : String[] = Directory.GetFiles( selectedPath, "*", SearchOption.AllDirectories );
     for( var file : String in fileEntries )
     {
         file = file.Replace( "\\", "/" );
         file = file.Remove( 0, realPath.Length );
         AssetDatabase.ImportAsset( file );
     }
 }
Comment
Add comment · Show 5 · 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 · Aug 09, 2011 at 11:05 AM 0
Share

cool! very interesting. Didnt know I could use AssetDatabase object without having the real Unity asset server.

avatar image Waz · Aug 09, 2011 at 11:43 AM 2
Share

AssetDatabase is for everyone, it's the (local) database of assets in your project.

avatar image Joshua · Aug 09, 2011 at 11:46 AM 1
Share

As Warwick says, it's the API you use from inside Unity to reference stuff inside your project folder. Also means you can, in edit mode, load in stuff without using Resources.Load.

avatar image BerggreenDK · Aug 09, 2011 at 12:10 PM 0
Share

Yummy! thanks for making this so obvious to me now. Thanks a lot! Great!

avatar image Abigail788 · Jan 23, 2020 at 10:59 AM 0
Share

AssetDatabase is for everybody, it's the (nearby) database of advantages in your venture.

avatar image
2

Answer by T_Strijker · Jan 23, 2020 at 08:26 AM

For people looking for an easier way. I found that calling AssetDatabase.ImportAsset method with the ImportAssetOptions.ImportRecursive and ImportAssetOptions.DontDownloadFromCacheServer options re imports everything in a folder.

string folderPath = "Assets/Art/"; AssetDatabase.ImportAsset(folderPath , ImportAssetOptions.ImportRecursive | ImportAssetOptions.DontDownloadFromCacheServer);

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
1

Answer by kabel · Sep 04, 2011 at 11:07 AM

i needed this to reload screenshots that i use as savegame thumbnails. just saying that this did the job for me:

 AssetDatabase.Refresh();
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 poolts · Aug 08, 2011 at 10:19 PM

Why would you need to reimport?

Any directories within the resource folder can be accessed with Resources.Load() and obviously if you overwrite a resource, which you have pointed to in your could it will be automatically "reimported" anyway. If this isn't what you looking for, comment back :)

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 BerggreenDK · Aug 09, 2011 at 11:06 AM 0
Share

we often ajust the fbx models and needs to reimport certain folders. Sometimes we also add new fbx or remove some of the old ones, so we remove them all from a folder and replace them with the "active" one. Then we do a reimport.

avatar image
0

Answer by mahri726 · Apr 18, 2013 at 04:28 PM

I still don't get it. You copy the script in a txt flile, name it randomly and place it inside Editor folder in Unity installation dirrectory? It doesn't work for me. I hope that this script would solve my problem: when I import a big pack of assets linked together(by copying all the folders of the pack inside Assets folder), when Unity imports all, it crashes. If I import only parts of assets, all the links are broken.

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

10 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

Related Questions

How do I programmatically assign a GameObject to a prefab? 6 Answers

Can I generate prefab instances based on locators inside a 3d model file? 2 Answers

How to Rename Sprite Slices in Script Without Breaking References 3 Answers

Creating a complex prefab during asset postprocessing 1 Answer

Model Importer fbm folder is still created 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