- Home /
Texture importer script: How to avoid resetting value when make changes
Hi everyone,
I want to change the default texture importer settings, so that the [Pixels to Units] = 1. After some research, I use this Editor script...
using UnityEngine;
using UnityEditor;
public class ChangeImporterSetting : AssetPostprocessor
{
void OnPostprocessTexture(Texture2D texture)
{
TextureImporter importer = assetImporter as TextureImporter;
importer.spritePixelsToUnits = 1;
Object asset = AssetDatabase.LoadAssetAtPath(importer.assetPath, typeof(Texture2D));
if (asset)
{
EditorUtility.SetDirty(asset);
}
else
{
importer.spritePixelsToUnits = 1;
}
}
}
It’s work. When I add a texture, it's default [Pixels to Units] is 1.
The problem is that when I change the setting for some texture, then save the scene, the changed setting resets to default value. For example, I change "example.png" [Pixels to Units] = 2, then save the scene, "example.png" [Pixels to Units] reset back to 1.
Could you suggest some change to the code to resolve the said problem?
Thank you.
Your answer
![](https://koobas.hobune.stream/wayback/20220613162355im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to skip already imported textures on AssetPostprocessor change? 3 Answers
Only PostProcess/PreProcess on new assets 1 Answer
change textures without changing the original file 0 Answers
AssetPostprocessor, AssetImporter set spritePackingTag invalid, Can't change texture meta. 0 Answers
How do I mark an asset as processed in AssetPostprocessor class 0 Answers