• 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
0
Question by bradowado · Dec 12, 2012 at 09:16 AM · texturematerialfbx

Set material main texture during FBX import

Does anyone know how to force Unity to always assign the main texture to be the color texture assigned in Maya? In Maya, when you assign a color texture (e.g. UnityProject/Assets/Textures/Texture1.png) to a material, export the FBX and import into Unity, the color texture will be assigned to the main texture of the imported material. However, if you change the color texture assigned to the material in Maya and re-export (e.g. Texture1.png -> Texture2.png) the material in Unity will still use the original color texture (Texture1.png) as the main texture. I have embedded media turned off in the FBX export settings, however, I get the same results with embedded media turned on. I have both of the textures in a folder named "Textures" in the same folder as the FBX. For the FBX import settings, I have Material Naming = From Model's Material. I don't want to have to use Material Naming = By Base Texture Name because I want one material in Maya to equal one material in Unity.

Below is my current code where I attempt to find the color texture assigned to the material in the FBX. However, if I assign "Texture2" to the model in Maya and import into Unity, it prints out "Texture1". I expected it to print out "Texture2"...perhaps I need to use a function other than OnPostprocessModel, something earlier in the asset processing order of operations?

 using UnityEngine;
 using UnityEditor;
 using System;
 using System.Collections;
 using System.Collections.Generic;
 using System.IO;
 using System.Text;
 
 public class AssetImportSettings : AssetPostprocessor
 {
     void OnPostprocessModel (GameObject go)
     {
         //Get the renderers in the FBX
         Renderer[] fbxRenderers = (Renderer[])go.GetComponentsInChildren<Renderer> ();
 
         for (int i = 0; fbxRenderers != null && i < fbxRenderers.Length; i++) {
             if (fbxRenderers [i].sharedMaterials == null) {
                 continue;
             }
             
             //Go through each material in the FBX
             for (int j = 0; j < fbxRenderers[i].sharedMaterials.Length; j++) {
 
                 string materialName = fbxRenderers [i].sharedMaterials [j].name;
                 
                 //Look to see if there is a texture assigned to the material. Print the name if there is one.
                 if (fbxRenderers [i].sharedMaterials [j].mainTexture != null) {
                     string textureName = fbxRenderers [i].sharedMaterials [j].mainTexture.name;
                     Debug.Log (materialName + "'s Main Texture = " + textureName);
                 } else { 
                     Debug.Log (materialName + " has no Main Texture.");
                 }
             }
         }
     }
 }
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Texture not woking with any FBX model imported from Blender. 2 Answers

FBX MODELS NOT GENERATING TEXTURES!!!!! 2 Answers

Problems with materials import from Maya 1 Answer

Material not shown on imported FBX sphere 0 Answers

texture not applied, despite many attempts 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