• 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 /
  • Help Room /
avatar image
0
Question by Shadoninja · May 05, 2018 at 03:25 AM · assetpostprocessor

My custom AssetPostprocessor.OnPreprocessTexture() logic is being run every time my project is saved

I used this tutorial to get some default import settings working, but I can no longer change any setting that is defined in my custom import class. The moment I hit "Apply," the class is called and the new values get reset back to the custom defaults. I just want this to be run the very first time an asset is imported, not constantly.

Here is my version of the code:

 // -------------------------------------------------------------------
 // - A custom asset importer for Unity 3D game engine by Sarper Soher-
 // - http://www.sarpersoher.com                                      -
 // -------------------------------------------------------------------
 // - This script utilizes the file names of the imported assets      -
 // - to change the import settings automatically as described        -
 // - in this script                                                  -
 // -------------------------------------------------------------------
 
 
 using UnityEngine;
 using UnityEditor;  // Most of the utilities we are going to use are contained in the UnityEditor namespace
 
 // We inherit from the AssetPostProcessor class which contains all the exposed variables and event triggers for asset importing pipeline
 internal sealed class CustomAssetImporter : AssetPostprocessor {
 
     #region Methods
 
     //-------------Pre Processors
 
     // This event is raised when a texture asset is imported
     private void OnPreprocessTexture() {
         // I prefix my texture asset's file names with tex, following 3 lines say "if tex is not in the asset file name, do nothing"
         var fileNameIndex = assetPath.LastIndexOf('/');
         var fileName = assetPath.Substring(fileNameIndex + 1);
 
         if(!fileName.Contains(".png")) return;
 
         // Get the reference to the assetImporter (From the AssetPostProcessor class) and unbox it to a TextureImporter (Which is inherited and extends the AssetImporter with texture specific utilities)
         var importer = assetImporter as TextureImporter;
         
         importer.spritePixelsPerUnit = 32;
         importer.filterMode = FilterMode.Point;
         importer.textureCompression = TextureImporterCompression.Uncompressed;
     }
 
     // This event is raised every time an audio asset is imported
     // This method does nothing at the moment, just a skeleton to fill in if we ever need to do audio specific importing
     // Imports audio assets in the default way without changing anything
 //    private void OnPreprocessAudio() {
 //        var fileNameIndex = assetPath.LastIndexOf('/');
 //        var fileName = assetPath.Substring(fileNameIndex + 1);
 //
 //        if (!fileName.Contains("snd")) return;
 //
 //        var importer = assetImporter as AudioImporter;
 //        if(importer == null) return;
 //    }
 
     #endregion
 }
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

137 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to start coding with AssetPostprocessor? 1 Answer

Create prefab from model in AssetPostprocessor without losing mesh connections? 3 Answers

Assigning Asset Bundle in Script 2 Answers

AssetPostprocessor and reimporting only some fbx 0 Answers

Create Prefabs for Sprites 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges