Can i change the default import settings?

There are two settings (bugs?) on imported files that are making me miserable

PNGs: isReadable is not set
3DSMax: scale set to 0.01

The first makes my textures unreadable to my application and blows things up. The second shrinks all my models to 1/100th of their normal size

Is there a way to make Unity not do this when adding a new asset?

It wouldn’t be too awful a problem except i have hundreds of both and we’re adding a few dozen new ones each week (it’s a fashion game, so we have lots of little shoes, textures, etc.). All are (and, for our game, must be) in the same folder. Unity has no sort by date option in the editor so it’s not easy to find the new additions. If i manually set these values, it takes half an hour or more and i invariably miss one, catching it only when something blows up

Option 2: We have an engine script to fix this automatically. Pretty nice but it takes half an hour to run and pegs my CPU so nothing else works while it’s going. Everyone on my team has to do this several times a week, so we’re losing noticeable amounts of time

Yes, we could re-work our asset management process to minimize how often this happens, but right now, it’s kind of painful

So, fingers crossed, i’m asking - is there a way to have Unity, by default, turn on isReadable for images or use the proper scale of 1 for models?

You can write small editor scripts like this to change default behaviour.

this script forexample disables importing of animations and resets the scale value to 1.0:

using UnityEngine;
using UnityEditor;
using System;

public class FBXScaleOverride : AssetPostprocessor {
    void OnPreprocessModel() {
		ModelImporter importer = assetImporter as ModelImporter;
		String name = importer.assetPath.ToLower();
		if (name.Substring(name.Length - 4, 4)==".fbx") {
			importer.globalScale = 1.0F;
			importer.generateAnimations = ModelImporterGenerateAnimations.None;
		}
    }
}
1 Like

It was good… if it worked :frowning:

Assets/SCRIPTS/DefaultMeshImportSettings.cs(2,1): error CS0246: The type or namespace name `UnityEditor' could not be found. Are you missing a using directive or an assembly reference?

Editor scripts must be placed in a directory called ‘editor’ to compile properly. The directory can be anywhere in your asset folder.

Ahhh yes sorry, I have put it in SCRIPTS editor :sweat_smile: :sweat_smile: :sweat_smile:
Thank you man, you saved me around 10 seconds on import on each mesh :smile:

I also recently needed that and I have found this:

http://wiki.unity3d.com/index.php/ModelImporterPresetManager

This was intended for Unity 3.5, but works even in the latest 5.5 version, although some settings are missing.
I have updated this script for 5.5, adding the rest of the settings - if someone needed that.

Sorry for reviving this old post with a slightly off-topic request. But can you update this code on the wiki page you linked? It will help (potentially a lot of) future users with this issue.

This is it.
I made the updates, but haven’t had an opportunity to test it yet.
Check it in action and let me know. If it’s fine I could update it on wiki.

7232776–870508–ModelImporterPresetManager.cs (25.1 KB)

great, these answers are what i need
I’m impress that you guys got this skill in the year 2010.
What did I do on these years,
I wish we could meet at the same period

I did not fully test it’s parmater, but it seems fine.

1 Like

Hi,

your script is very useful in Editor, but how i can build my project with it?
Or it’s imposible?

Best regards.

You put it in a folder named “Editor”

See here.

Yes, but will it work after in runtime?
I thought that all what is in the Editor folder is working only in editor.

It’s a script for changing how the editor imports assets. That only happens in the editor. The assets won’t need to be imported again when you build the game.

Sorry for long answer.
I didn’t say that i am developing a game.
It’s a system where you can import and edit a 3dModel.
That’s why i’m searching how to import 3d Model in runtime.

Ah. That’s not supported by default in Unity. All the scripts in this thread works with Unity’s built-in editor only imports.

If you want to import 3d models at runtime, there’s a bunch of third party assets that does that in the Asset store.

1 Like

Thanks, Aubergine, for being such an asset to the forums! (Several other posts have helped me in the past.)

I’ve been frustrated for years with the long wait on large model imports, with the subsequent ticking of boxes, waiting, switching tabs, applying, waiting some more, etc. I looked into a solution a while back but didn’t find anything, until this post. (The missing magic was “AssetPostprocessor”.)

I’ve thrown together a script for model imports that works for 99% of my needs. Thought I’d share it:

using UnityEditor;

public class ModelImport : AssetPostprocessor {
    void OnPreprocessModel() {
        ModelImporter importer = assetImporter as ModelImporter;
        string name = importer.assetPath.ToLower();
        string extension = name.Substring(name.LastIndexOf(".")).ToLower();
        switch (extension) {
            case ".3ds":
            case ".fbx":
            case ".blend":
                importer.globalScale = 1.0F;
                importer.meshCompression = ModelImporterMeshCompression.Medium;
                importer.optimizeMesh = true;
                importer.importBlendShapes = false;
                importer.addCollider = false;
                importer.weldVertices = true;
                importer.importVisibility = false;
                importer.importCameras = false;
                importer.importLights = false;

                importer.importNormals = ModelImporterNormals.Import;
                importer.importTangents = ModelImporterTangents.CalculateMikk;

                importer.importAnimation = false;
                importer.animationType = ModelImporterAnimationType.None;
                importer.generateAnimations = ModelImporterGenerateAnimations.None;

                importer.importMaterials = true;
                importer.materialLocation = ModelImporterMaterialLocation.External;
                importer.materialName = ModelImporterMaterialName.BasedOnMaterialName;
                importer.materialSearch = ModelImporterMaterialSearch.Everywhere;
                break;
            default:
                break;
        }
    }
}
5 Likes

Thanks you!

1 Like

The above code executes for every model imported, which can be a pain if you have a model that needs something different. I experimented with various ways of activating/deactiving the script, but the best workaround was to simply run via menu command. Since Unity persists the settings after import, you only have to do it once (per model, after initial import).

I also added the ability to crunch textures, which is essentially worth doing on every texture you import. (Crunching takes a fair amount of time whenever you make a change, so I typically just do this when I’m close to releasing a project.)

So, with the following script in your Editor folder, just right-click the model(s) and/or texture(s) you want to import with defined values, select the shortcut menuitem “Reimport with Defaults”, and go grab yourself a tasty beverage:

using UnityEditor;
using UnityEngine;

public class ReimportWithDefaults : ScriptableObject {
    [MenuItem("Assets/Reimport with Defaults")]
    static void ReimportWithDefaultsMenu() {
        foreach (string guid in Selection.assetGUIDs) {
            string path = AssetDatabase.GUIDToAssetPath(guid);
            AssetImporter assetImporter = AssetImporter.GetAtPath(path);
            Debug.Log(assetImporter.GetType());
            if (assetImporter is ModelImporter) {
                ModelImporter importer = AssetImporter.GetAtPath(path) as ModelImporter;
                importer.useFileScale = false;
                importer.meshCompression = ModelImporterMeshCompression.Medium;
                importer.isReadable = false;
                importer.optimizeMesh = true;
                importer.importBlendShapes = false;
                importer.addCollider = false;
                importer.weldVertices = true;
                importer.importVisibility = false;
                importer.importCameras = false;
                importer.importLights = false;

                importer.importNormals = ModelImporterNormals.Import;
                importer.importTangents = ModelImporterTangents.CalculateMikk;

                importer.importAnimation = false;
                importer.animationType = ModelImporterAnimationType.None;
                importer.generateAnimations = ModelImporterGenerateAnimations.None;

                importer.importMaterials = true;
                importer.materialLocation = ModelImporterMaterialLocation.External;
                importer.materialName = ModelImporterMaterialName.BasedOnMaterialName;
                importer.materialSearch = ModelImporterMaterialSearch.Everywhere;
                importer.SaveAndReimport();
            } else if (assetImporter is TextureImporter) {
                TextureImporter importer = assetImporter as TextureImporter;
                importer.crunchedCompression = true;
                importer.compressionQuality = 75;
                importer.anisoLevel = 2;
                importer.SaveAndReimport();
            }
        }
    }
}

The defaults are values I like in most of my projects. YMMV.

3426828–270593–ReimportWithDefaults.cs (2.13 KB)

2 Likes

Look through code of @kideternal , so i can make my own code to post processing every image i want force Enable Read/Write when import to folder i want. Just share this! :slight_smile:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class ImagePostProcress : AssetPostprocessor
{
    void OnPostprocessTexture(Texture2D texture)
    {
        TextureImporter importer = assetImporter as TextureImporter;
        string assetPath = importer.assetPath;

        if (!IsResourceImage(assetPath))
            return;

        importer.isReadable = true;
        Debug.Log("Set Readable for image: " + assetPath);
    }

    private bool IsResourceImage(string path)
    {
        if (path.Contains("Resources/Textures/ImagePacks"))
            return true;

        return false;
    }
}

3428012–270731–ImagePostProcress.cs (680 Bytes)

2 Likes