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
1
Question by rodeowild · May 25, 2017 at 02:54 PM · editor-scriptingtexture2dcompressionassetpostprocessorimport settings

How can I change the default max size of a texture from an editor script (in import settings)?

I'm importing a bunch of high resolution images. I need the images look as they do in photoshop. The way I found to do this is by going to the specific sprites import settings, turning on "Override for PC, Mac and Linux Standalone" (in the bottom section labeled default) and setting the "max size" property to 8192. This works pretty well.

Unfortunately I need to do this to many images, which will be tedious and eat up a lot of time. I know I can use the AssetPostprocessor to alter the import settings of a sprite when it is imported (using OnPostprocess set of functions) or before it is imported (using the OnPreprocess set of functions). However, I don't know how to access the "max size" property from a script. How can I do that?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by monotoan · Nov 10, 2017 at 09:41 PM

Here's a way to do this that worked for me. It's a little awkward because it involves creating a temporary struct for import settings, reading values into that struct from the texture importer system, changing some of those values, then passing the changed struct back to the importer. But I've tried to comment everything clearly below!

 using UnityEngine;
 using UnityEditor;
 // ^^^ Make sure you add the UnityEditor using directive! ^^^^
 
 //Also make your script inherit from AssetPostprocessor, NOT Monobehaviour
 public class SetTexImportSizeViaScript : AssetPostprocessor
 {
     //function that's called when a texture starts to be imported
     void OnPreprocessTexture()
     {
         //get a reference to the built-in TextureImporter...
         TextureImporter importer = (TextureImporter)assetImporter;
 
         //create a new empty TextureImporterSettings struct...
         TextureImporterSettings textureImporterSettings = new TextureImporterSettings();
 
         //read the current import settings from the Texture Importer
         //into our new importer settings struct (basically filling the empty struct with values)
         importer.ReadTextureSettings(textureImporterSettings);
 
         //change the maxTextureSize setting in our settings struct
         textureImporterSettings.maxTextureSize = 32;
 
         //pass the settings struct, with the changed maxTextureSize value, back into the importer
         //(e.g. apply the changed settings to the importer)
         importer.SetTextureSettings(textureImporterSettings);
     }
 }

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Modify sprite geometry using AssetPostprocessor 0 Answers

2D sprite renders a small part of another one with "Sprite Mode : Multiple" 0 Answers

Does Unity decompress Truecolor RGBA format textures when loading? 0 Answers

Stop Texture2D Compression 0 Answers

Material.mainTexture not working outside of runtime? 1 Answer


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