Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
3
Question by booger_sugar · Apr 01, 2010 at 06:10 PM · textureeditor-scriptingsettingsimporter

Editor class "Texture Importer" + Apply import settings question

I created an editor script that helps me change the settings on textures automatically so that I don't have to. It works for the most part except for changing the texture importer isReadable = true. If the texture isn't readable, a dialog box pops open saying "Unapplied import settings" and then asks me to Apply or Revert. Even when I press "Apply", I double-check the texture and isReadable is still set to false. Is there any code that will allow me to "Apply" the import settings?

Here's a snippet of my code (I'm using C#):

string path = AssetDatabase.GetAssetPath(texture); TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;

if (textureImporter.isReadable == false) { textureImporter.isReadable = true; AssetDatabase.ImportAsset(path); }

Comment
Add comment · Show 1
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 jahroy · Oct 19, 2011 at 03:28 AM 0
Share
  • See Favo Yang's answer **

6 Replies

· Add your reply
  • Sort: 
avatar image
8

Answer by Digitalos · Jan 02, 2011 at 08:14 AM

I've also been trying to get this working, and have found a few things. This is the bare minimum code you need to get it working, and also it has to be in this order - if you change the filtering/anis/clamp modes, and -then- change the importer settings, it loses the previous changes. This is as of Unity 3.1, tested and confirmed on a Win7 PC.

TextureImporter tImporter = AssetImporter.GetAtPath( path ) as TextureImporter; if( tImporter != null ) { tImporter.mipmapEnabled = ...; tImporter.isReadable = ...; tImporter.maxTextureSize = ...; AssetDatabase.ImportAsset( path, ImportAssetOptions.ForceUpdate ); }

     UnityEngine.Object t = AssetDatabase.LoadAssetAtPath( path, typeof( T ) );
     if( t != null ) {
         ( (Texture2D)t ).filterMode = ...;
         ( (Texture2D)t ).wrapMode = ...;
     }

I hope that helps :)

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 Andy Korth · Apr 14, 2011 at 09:46 PM 0
Share

This did work for me. All my old pre-Unity 3.0 texture scripts didn't require a forced update, but now it seems they do.

avatar image
4
Wiki

Answer by Carlos Ulloa · May 22, 2010 at 03:01 PM

You should specify ImportAssetOptions.ForceUpdate when calling ImportAsset, in your case:

AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);

Comment
Add comment · Show 6 · 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 booger_sugar · May 24, 2010 at 04:41 PM 0
Share

I just tried that and the dialog box still appears and the same thing that I described before still happens.

avatar image whittlong · Oct 12, 2010 at 04:42 PM 0
Share

i'm experiencing the same issue with trying to procedurally edit import settings. have tried every variation of the ImportAssetOptions, and every Save/Refresh/Load method the AssetDatabase class has to offer. If anyone solves this one, would love to see it posted here.

avatar image Jake-L · Mar 29, 2011 at 01:38 PM 0
Share

$$anonymous$$e, too. I noticed that when I try to change multiple textures in a loop only the last showed the question and ignore the changes. All other changes were applied properly!

avatar image Jake-L · May 03, 2011 at 02:53 PM 0
Share

After looking into it again it shows that all settings apply properly except for the texture currently been previewed in the Inspector window. I'll submit a bug report...

avatar image jahroy · Oct 19, 2011 at 03:27 AM 0
Share
  • See Favo Yang's answer **

If you click the "revert" button (in s$$anonymous$$d of apply) it actually works. The bug is in the display dialog.

I wonder if this is $$anonymous$$ac only...

Show more comments
avatar image
2

Answer by Lucas Meijer 1 · Apr 01, 2010 at 09:03 PM

You'll have more luck when trying a AssetPreProcessor instead. (In fact, I didn't even know you could do what your example shows. Learn something new every day :) )

Here's a link to the help which includes an example usage:

http://unity3d.com/support/documentation/ScriptReference/AssetPostprocessor.OnPostprocessGameObjectWithUserProperties.html

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
2

Answer by Favo-Yang · May 31, 2011 at 05:52 AM

I have the same issue by using the texture import settings from Unity Community wiki. If I click apply on the popup, then the current active selection texture object won't get update. Though I didn't find a perfect solution, but if you click revert on the popup, everything works fine.

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 jahroy · Oct 19, 2011 at 03:24 AM 0
Share

Thank you! Thank you! Thank you!

avatar image AndyKorth · Dec 07, 2011 at 10:19 PM 0
Share

Confirmed! This also worked when I ran into problems with the $$anonymous$$odelImporter.

avatar image
0

Answer by jahroy · Oct 19, 2011 at 03:11 AM

I am reproducing the same issue when using TextureImporter.SetPlatformTextureSettings().

My editor script works fine (and updates the platform override settings) only if the texture in question is NOT selected.

I notice that the texture settings script from the wiki sets Selection.objects to an empty Object array before it operates on textures. I tried using the same approach in my script, but it throws an InvalidCastException.

It might be worth mentioning that (for some silly reason) I'm using javascript...

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 jahroy · Oct 19, 2011 at 03:24 AM 0
Share

Favo Yang's answer solved my problem!

  • 1
  • 2
  • ›

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Auto switch max size of a selected texture in Project window 0 Answers

How do I import TGA, DDS, GIF, PCX and BMP files at runtime? 1 Answer

Texture importer, changing original file size 0 Answers

Any way to export generated bump map from the Editor? 1 Answer

Default Texture Platform/Format settings 2 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