x


How do I mimic the Assets->Reimport menu item?

I need to programmatically recreate what Assets->Reimport does.

    [MenuItem ("Assets/Seriously. Reimport")]
static void ReimportJeez() {
	UnityEngine.Object obj = Selection.activeObject;
	string path = AssetDatabase.GetAssetPath(obj);

	AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ImportRecursive);
}

This does not work. Select a folder and choose the menu item and according to the console log the only thing that gets touched is the folder that is selected. The recursive option doesn't seem to be doing anything.

more ▼

asked Nov 25 '09 at 10:17 PM

Jonathan Czeck gravatar image

Jonathan Czeck
51 4 5 9

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

2 answers: sort voted first

I just looked into this, and it turns out that we have just defined the value of the ImportAssetOptions.ImportRecursive flag wrong. It's currently defined as 128, but needs to be 256. I'll make sure this is fixed in 2.6.1, in the meantime, instead of ImportAssetOptions.ImportRecursive, (256 as ImportAssetOptions) should work.

more ▼

answered Nov 26 '09 at 03:45 PM

jonas echterhoff gravatar image

jonas echterhoff ♦♦
9.8k 7 23 104

Jonas, it might be a good idea for you guys to add this info to you documentation until it is fixed. I spent a large amount of time today attempting to figure out why it was not rebuilding the directory I specified recursively.

Apr 08 '10 at 09:16 PM Bill

Bill, are you saying that you are still seeing this issue in Unity 2.6.1? If you are still on 2.6.0 (or older), please upgrade.

Apr 09 '10 at 08:58 AM jonas echterhoff ♦♦
(comments are locked)
10|3000 characters needed characters left

I am thinking maybe you can't do recursive on that path (/Assets/MyAsset.asset) but need to call the recursive function on the folder it exists in. I don't know them from the top of my head but I think System.IO.Path and System.IO.FileInfo has all the methods you need to easily extract the path to the folder the asset is inside.

more ▼

answered Nov 26 '09 at 10:00 AM

Statement gravatar image

Statement ♦♦
20.1k 35 70 175

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

x349

asked: Nov 25 '09 at 10:17 PM

Seen: 1977 times

Last Updated: Nov 25 '09 at 10:17 PM