Possible to make editor script to auto set Needle Compression settings?

I assume this can be done just asking before I attempt it at work tomorrow, I already have an editor scripts for other projects that checks if an imported file - on import only - is a texture, then checks its name to see if it contains ‘Normal’ and marks it as a normal texture.

Can I do something similar with Needle Import settings via Editor script to find out if a texture is called Normal/Metallic etc and change it’s compression type to UASTC otherwise set ETC1S?

Too often I have been in a hurry exporting a compressed glb from Needle for other things and realising I over compressed the textures

Original Post on Discord

by user 103054507105067008

Yes should be no problem. Can send you info tomorrow

Actually just derive from the Texture compression settings component and add it to the scene somewhere

Sure, would be useful if I can editor script it up to automate what values are set per texture on import though, can send a sample of what I usually do

by user 103054507105067008

@marcel :cactus: This is the kind of script I have currently - was wondering if I can edit it to change compression type for Needle there?
AssetPreprocessor.cs

by user 103054507105067008

but thats not called for subassets is it? since originally you dont have import settings in unity for subassets

So if you have the TextureCompressionSettings component in your scene then it will choose uastc for normals automatically. If you override the TextureCompressionSettings and add it to your scene you get on export every used texture + slot and can return the compression type you want

I am using this for non-sub assets just regular textures from a GLTF + Separate file in my current workflows so each GTLF comes with a textures folder that has the raw textures in it. Would it work for that?

by user 103054507105067008

That is only good if I want all textures exported to use the same compression type, but in my case I want albedo to use ETC1S only and Normal/metallic maps to use UASTC so I want to script it in an editor script on texture import

by user 103054507105067008

This solution is totally unrelated to how your textures exist on disc.

I also exposed NeedleAssetSettingsProvider which you can use to update the import settings - doesnt matter if subassets or not.

No its not. You can set per texture

As i said - it gets called per texture :slightly_smiling_face:

You implement this method CompressionSettingsModel GetSettings(IExportContext context, TextureExportSettings texture, string textureSlot)

Is there any example of how to call NeedleAssetSettingsProvider on texture import? I’m hoping to just set up an editor script to check the texture name for normal/metallic and set it there on import

by user 103054507105067008

Sweet, I’ll try that!

by user 103054507105067008

It has static methods for getting and setting the settings (but you need the texture loaded for setting the settings).

I’ll make an example script and post it back as others might find it useful

by user 103054507105067008

I would suggest we try first what works best :slightly_smiling_face:

Struggling to find where this fits with

class AssetPreprocessor : AssetPostprocessor
{
    void OnPreprocessTexture()
    {}
}

by user 103054507105067008

see this