Search Unity

[RELEASED] TextureAssign - Automatically assign all textures to all materials

Discussion in 'Assets and Asset Store' started by Elecman, Sep 24, 2017.

  1. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,371
    TextureAssign_2.png

    Assigning textures from Substance Painter to materials in Unity is incredibly tedious and time consuming. Each material has 4 or 5 textures which you need to find, then drag and drop onto the material. TextureAssign solves this problem by automating this process. It works by name-matching textures with materials.

    The script can also detect redundant textures (all pixels have the same value) and replace them with a single color on the material.

    Although it is designed for textures exported from Substance Painter, it should work for any texture with this naming convention:
    [material name]_[textureType]

    For example:
    top part_AlbedoTransparency.png
    top part_AO.png
    top part_MetallicSmoothness.png
    top part_Normal.png

    I suppose I could make the naming convention logic more flexible to allow for more configurations. Let me know if there is any interest.

    Get the script and manual here:
    https://share.allegorithmic.com/libraries/2396
    https://drive.google.com/file/d/1v0aFn3UFjT5ArdUGqe8mL5qmtb977qIm/view?usp=sharing
     
    Last edited: Mar 4, 2024
    BitPax and theANMATOR2b like this.
  2. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,371
    What I am particularly interested in is if you are using multiple naming conventions in one project. For example, some textures might use:

    top part_AlbedoTransparency.png
    Others use:
    top part_albedo.png
    And yet others:
    AlbedoTransparency_top part.png

    Also, do you have textures which do not have part of the material name in the texture name?
     
  3. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    I'm sure a lot of asset packs have generic naming conventions for individual models Albedo.tga, normal.png.
    Might consider that as an alternate convention, although it is pretty negligent on the devs part imo.

    btw - this is a pretty nice idea. I'm not a substance user (yet) but will test it as a non-substance user. From reading the posts on share - Is it stable now?
     
  4. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,371
    If the texture doesn't contain the material name then at the very least the folder which contains the textures should contain the material name. Otherwise there is no way to match the two automatically AFAIK.

    As for stability, some users on Substance Share have reported that it crashes Unity in some cases. Unfortunately, no one has sent me a reproducible project so it will be nearly impossible to fix. But if that happens to you, please do let me know. It can also appear to crash when the operation takes a very long time though. There is an option to replace textures with a single color (if the entire texture has the same color) but this is very time consuming.
     
    theANMATOR2b likes this.
  5. redemprez

    redemprez

    Joined:
    Aug 14, 2017
    Posts:
    29
    It works ok with Standard Built-in pipeline, which is great and thanks for that. But I report that it does not work with HDRP pipeline in Unity 2018.3 b06
     
  6. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,371
    Ok, I will have a look.
     
  7. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,371
    Last edited: Mar 4, 2024
    BitPax likes this.
  8. gamegirl1984

    gamegirl1984

    Joined:
    Nov 6, 2014
    Posts:
    102
    Nothing is happening for me. Example: my material name is: characterFace and the texture name is: characterFace_AlbedoTransparency. I click on the material, select the folder where the textures are and then click on Assign to selected object. It fails.
     
  9. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,371
    I did a quick test and it seems to work so I am not sure what it causing it. If you send me a small repo I will have a look.
     
    Last edited: Nov 28, 2018
  10. gamegirl1984

    gamegirl1984

    Joined:
    Nov 6, 2014
    Posts:
    102
    Sorry, i created a new project and just made some test stuff and it does work.

    I do have a question though. Is there any way to tweak the script so it uses custom names? For textures? Mine come over from iclone C3 and are named differently. And also use the Standard Roughness shader. Is there anyway to change the shader? Please let me know. This is great. What about creating a public variable so we can input the name of the texture or something??

    Also, when it comes to underscores. Can we change it so the underscores don't cause issues?
     
    Last edited: Nov 28, 2018
  11. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,371
    Yes, it is possible to use custom names for the different maps. To do this, open the script and look for this line:
    Code (CSharp):
    1. //These are the names added to the textures when exported by Substance Painter.
    You can change the names below on the right accordingly.

    Can you give an example texture name you have?

    Making the texture type description in the texture name (_AlbedoTransparency for albedo for example) configurable in a setting instead of changing the source is of course a better idea, but it is a quick fix. This is the only thing you can easily change yourself at this time.

    if you don't want to use the underscore character as a spacer, the source has to be changed at various places. I will have a look at it.

    The Unity build-in pipeline standard shader (metal/rough version) is already supported. The Specular shader is supported too but not tested. The SRP HD and LW standard shaders are supported too. Or do you mean the script can handle different shaders? In that case, it could be that it works out of the box as long as the texture names from the shader are the same.

    For example, most shaders use _MainTex for the albedo texture, so in case of the albedo texture, the script just matches a texture which ends in _AlbedoTransparency to a texture slot called _MainTex in the shader. In case of the HD standard shader, _MainTex is called _BaseColorMap. What the script does is plug the texture in any material slot which has a compatible shader name. This could be made more flexible so it is configurable for custom shaders, but if those shaders also use keywords to turn the textures on and off, it gets more complicated. Let me know what it is exactly you are looking for with the different shader.

    Edit:
    You can also use this tools if you need something fast. It does not have all features TextureAssign has (replace uniform textures with single color value, set opaque/transparent material type, HDRP shader, source code, apply to selected), but it does have some more which TextureAssign does not have.
    https://assetstore.unity.com/packages/tools/utilities/easyimport-105445
     
    Last edited: Nov 29, 2018
    As_day and BitPax like this.
  12. Elecman

    Elecman

    Joined:
    May 5, 2011
    Posts:
    1,371
    Last edited: Mar 4, 2024
    As_day and BitPax like this.
  13. As_day

    As_day

    Joined:
    Nov 21, 2013
    Posts:
    5