2

I am trying to make an editor script to set the import settings for my images. I don't want to do this manual since I need to import hundreds of images.

So I want to set edit the default import settings.

I tried the following:

using System.Collections;
using System.Collections.Generic;
using UnityEditor;

[InitializeOnLoad]
public class EditorSettings : Editor {

    private static TextureImporter CustomImporter;

    static EditorSettings()
    {
        CustomImporter.npotScale.None; // see below for error.
    }
}

the error I get is the following:

Member 'TextureImporterNPOTScale.None' cannot be accessed with an instance reference; qualify it with a type name instead

How do I do this? (it has something to do with how unity lets me acces the properties.)
And is this even the correct way to change the import settings for images?

Let me know if anything is unclear so I can clarify.

FutureCake
  • 2,614
  • 3
  • 27
  • 70
  • Possible duplicate of [Member '' cannot be accessed with an instance reference](https://stackoverflow.com/questions/1100009/member-method-cannot-be-accessed-with-an-instance-reference) – Remy Aug 17 '18 at 15:34

1 Answers1

1

How do I do this? And is this even the correct way to change the import settings for images?

No. This is not how to change the import settings of images. To change the settings of an imported image, you have to create an Editor script that derives from AssetPostprocessor then change the image settings in the OnPostprocessTexture function which will be called when the image has finished importing. The image is changed with the TextureImporter class.

public class PostprocessImages : AssetPostprocessor
{
    void OnPostprocessTexture(Texture2D texture)
    {
        TextureImporter textureImporter = (TextureImporter)assetImporter;
        textureImporter.npotScale = TextureImporterNPOTScale.None;
    }
}
Programmer
  • 121,791
  • 22
  • 236
  • 328
  • just one more question, where do i need to place the script? And do i need to do anything other to make it change the images? – FutureCake Aug 17 '18 at 16:42
  • 1
    You create a folder called "Editor" in your Assets folder. Create a script named `PostprocessImages` in that "Editor" folder and copy the code in my answer to it. You must also add `using UnityEditor;` to it at the top. Note that there is also `OnPostprocessSprites(Texture2D texture, Sprite[] sprite)`. Depending on the type of image, you might need that instead of `OnPostprocessTexture(Texture2D texture)` used in my answer. Do the test your self and see which one get's called then stick to it. *You don't have to do anything else* – Programmer Aug 17 '18 at 16:46