x


Change an object's import settings in the editor

I got a mesh that I need to change the settings for. I found http://unity3d.com/support/documentation/ScriptReference/ModelImporter.html But I can't figure out how to use it. What I want is to simply do something like:

Mesh mesh; mesh.thisorthat = value;

from the editor. The model importer seems perfect for that, but I can't figure out how to assign a mesh to it.

more ▼

asked Jun 15 '11 at 09:07 PM

Johan 4 gravatar image

Johan 4
427 81 84 97

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

1 answer: sort newest

It sounds like you might be interested in writing an editor script.

You could write a function that gets invoked by a menu item that could do what you want.

One easy way to do it would be to use the Selection object, which allows you to select an object in the project or hierarchy and perform operations on it.

Selection:

http://unity3d.com/support/documentation/ScriptReference/Selection.html

MenuItem (with some nice example code):

http://unity3d.com/support/documentation/ScriptReference/MenuItem.html

Another way to reference an object from an editor script is to use the AssetDatabase or Resources classes.

AssetDatabase (allows you to load an asset based on its path among other things):

http://unity3d.com/support/documentation/ScriptReference/AssetDatabase.html

Resources (allows you to load assets from specific directories at runtime):

http://unity3d.com/support/documentation/ScriptReference/Resources.html

If you're talking about changing settings when assets are imported, you might want to look at the AssetPostprocessor class, which lets you specify various functions to get executed whenever various types of assets get imported:

http://unity3d.com/support/documentation/ScriptReference/AssetPostprocessor.html

more ▼

answered Jun 15 '11 at 09:42 PM

jahroy gravatar image

jahroy
3.2k 14 18 41

Yeah I am referencing my objects right now and that works, I can change the limited amount of options that mesh object has. But I need to change it's import properties. Like I reference it and then change import properties of it and then apply it or something.

Jun 16 '11 at 10:22 AM Johan 4

Here's some code I use to override image import settings for iOS builds.

It gets called from a MenuItem in an editor script.

It's basically copied directly from the wiki:

  static void SelectedChangeTextureFormatSettingsIOS(TextureImporterFormat newFormat) 
    {

        Object[] textures = GetSelectedTextures();
        Selection.objects = new Object[0];
        foreach (Texture2D texture in textures)  {
            string path = AssetDatabase.GetAssetPath(texture);
            TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
            textureImporter.SetPlatformTextureSettings("iPhone", 1024, newFormat);
            AssetDatabase.ImportAsset(path);
        }
    }

It looks like using a ModelImporter would be pretty similar.

Jun 16 '11 at 10:38 PM jahroy
(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:

x1678
x1366
x973
x128

asked: Jun 15 '11 at 09:07 PM

Seen: 1964 times

Last Updated: Jun 16 '11 at 10:38 PM