Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by unitylove · Mar 29, 2011 at 02:39 PM · assetpostprocessor

Changing Texture import default settings.

Every texture that gets imported by Unity defaults to "Filter Mode: Bilinear" and "Aniso Level: 1". I would like to change these defaults to Trilinear and Aniso 0. So I created the following Editor class:

using UnityEngine; using UnityEditor;

public class TexturePostprocessor : AssetPostprocessor { public void OnPostprocessTexture(Texture2D t) { t.anisoLevel = 0; t.filterMode = FilterMode.Trilinear; } }

Which does work. However I would like to change these values for individual textures manually in the editor after importing. When I do that and then save the scene, OnPostprocessTexture is being called again and resets the manually set values, which is undesirable for obvious reasons.

The documentation says "AssetPostprocessor lets you hook into the import pipeline and run scripts prior or after importing assets.". Why does saving the scene cause a reimport? How can I solve this problem?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
7
Best Answer

Answer by unitylove · Mar 30, 2011 at 02:19 PM

It seems I found a solution to my problem:

 using UnityEngine;
 using UnityEditor;
 
 public class TexturePostProcessor : AssetPostprocessor
 {
     void OnPostprocessTexture(Texture2D texture)
     {
         TextureImporter importer = assetImporter as TextureImporter;
         importer.anisoLevel = 0;
         importer.filterMode = FilterMode.Trilinear;
 
         Object asset = AssetDatabase.LoadAssetAtPath(importer.assetPath, typeof(Texture2D));
         if (asset)
         {
             EditorUtility.SetDirty(asset);
         }
         else
         {
             texture.anisoLevel = 0;
             texture.filterMode = FilterMode.Trilinear;          
         } 
     }
 }
             
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ABerlemont · Dec 27, 2018 at 05:20 PM 0
Share

can you explain what you did to solve it ?
or add some comments in your script example ?
Thanks!

avatar image ABerlemont ABerlemont · Dec 27, 2018 at 05:24 PM 0
Share

It seems that those lines manage the difference between editing the file after import and the first time it's imported

 Object asset = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D));
 if (asset != null){ editing in editor (like rena$$anonymous$$g) }
 else { on first import }
avatar image
2

Answer by Jessy · Mar 29, 2011 at 03:04 PM

You've got to change the settings for the importer, not the texture itself. Changing texture settings is for runtime use.

using UnityEngine; using UnityEditor;

public class TexturePostProcessor : AssetPostprocessor {

void OnPostprocessTexture () { var importer = assetImporter as TextureImporter; importer.anisoLevel = 0; importer.filterMode = FilterMode.Trilinear; }

}

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image unitylove · Mar 29, 2011 at 03:13 PM 0
Share

When I use your code, I can no longer change these parameters manually (via Inspector) after importing.

avatar image Jessy · Mar 29, 2011 at 04:11 PM 0
Share

Restart Unity. The code that you had before causes invisible persistent bugginess.

avatar image unitylove · Mar 30, 2011 at 07:36 AM 0
Share

Restarting Unity did NOT solve the issue. Whenever I drag the "Aniso Level" slider (or save the scene), OnPostprocessTexture() will be called, resetting the values.

avatar image Jessy · Mar 30, 2011 at 12:50 PM 0
Share

That was the problem for me. I only have the problem when I use your script, or after I use your script, then edit the script, and save, sometimes.

avatar image unitylove · Mar 30, 2011 at 01:32 PM 0
Share

$$anonymous$$ulti-part comment here, because of the character limit:

I have upgraded to Unity 3.3 and I am experiencing a different behaviour with your script now: When I (re)import a texture or drag the Aniso slider, I get the following error message:

Show more comments
avatar image
1

Answer by Andrey-Postelzhuk · Jul 15, 2014 at 03:00 PM

This is solution for me:

 public class TexturePostProcessor : AssetPostprocessor
 {
 
     void OnPreprocessTexture()
     {
         Object asset = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D));
         if (asset)
             return; //set default values only for new textures;
         
         TextureImporter importer = assetImporter as TextureImporter;
         //set your default settings to the importer here
     }
 
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by wkwan · May 20, 2015 at 08:05 PM

If you want to set defaults for your textures without writing postprocessor code, I made a simple asset that does just this:

https://www.assetstore.unity3d.com/en/#!/content/35747

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jellyberg · Jun 09, 2015 at 04:30 PM 0
Share

£10 seems a bit steep!

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to add a specific object from one array to another ? 1 Answer

Instantiate prefab in the editor 1 Answer

After AssetPostprocessor meshes seem to be gone. 2 Answers

AssetDataBase.ImportAsset not triggering AssetProcessor.PreProcessModel 0 Answers

Is there a hook for when you update files from the asset server? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges