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;
}
}
}
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?
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.
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
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.
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:
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:
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!
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;
}
}