x


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?

more ▼

asked Aug 08 '11 at 09:00 PM

BerggreenDK gravatar image

BerggreenDK
2.4k 54 62 75

(comments are locked)
10|3000 characters needed characters left

4 answers: sort newest

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 );
    }
}
more ▼

answered Aug 08 '11 at 10:58 PM

Joshua gravatar image

Joshua
6.4k 19 25 70

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

Aug 09 '11 at 11:05 AM BerggreenDK

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

Aug 09 '11 at 11:43 AM Waz

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.

Aug 09 '11 at 11:46 AM Joshua

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

Aug 09 '11 at 12:10 PM BerggreenDK
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Apr 18 at 04:28 PM

mahri726 gravatar image

mahri726
1 1

(comments are locked)
10|3000 characters needed characters left

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

AssetDatabase.Refresh();
more ▼

answered Sep 04 '11 at 11:07 AM

kabel gravatar image

kabel
66 1 2 2

(comments are locked)
10|3000 characters needed characters left

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 :)

more ▼

answered Aug 08 '11 at 10:19 PM

poolts gravatar image

poolts
46 1 1 6

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.

Aug 09 '11 at 11:06 AM BerggreenDK
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x970
x348

asked: Aug 08 '11 at 09:00 PM

Seen: 1051 times

Last Updated: Apr 18 at 04:28 PM