Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question FBX export does not include Textures when assigning _BaseColorMap during runtime

Discussion in 'Scripting' started by owiesniak, Oct 5, 2021.

  1. owiesniak

    owiesniak

    Joined:
    Jan 27, 2018
    Posts:
    6
    Trying to applying a texture dynamically during runtime to _BaseColorMap and exporting GameObject as FBX afterwards. Texture correctly applied to the shader and is also visible in Game View. But Texture is not assigned to _BaseColorMap in the exported FBX.

    I manually applied a texture before runtime to _BaseColorMap in Unity Editor and exporting FBX which works as expected.

    Not sure what's the difference here or why it is not included in the FBX when i assign it during runtime.

    Example Code

    unity.png

    Code (CSharp):
    1. // Init chip GameObject based on Prefab
    2. chip = Instantiate(chipPrefab, new Vector3(0, 0, 0), Quaternion.identity);
    3.  
    4. // Assign material to chip Mesh Renderer
    5. ringOutsideRenderer = chip.transform.Find("ring_outside").GetComponent<MeshRenderer>();
    6. ringOutsideRenderer.material = ringOutsideMaterial;
    7.  
    8. // Set texture on Mesh Renderer Material
    9. ringOutsideRenderer.material.SetTexture("_BaseColorMap", ringTexture);
    10.  
    11. // Export chip as FBX
    12. string filePath = Path.Combine(Application.dataPath, exportFileBasename + ".fbx");
    13. Object[] objects = new Object[1];
    14. objects[0] = chip;
    15. ModelExporter.ExportObjects(filePath, objects);
    16. Debug.Log("Export: " + exportFileBasename + ".fbx");
    17.  
    18. // Problem: FBX does not include textures applied
    19. // Research: Applying a texture to _BaseColorMap in Unity Editor and exporting FBX, includes texture
     
    Last edited: Oct 5, 2021
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
  3. owiesniak

    owiesniak

    Joined:
    Jan 27, 2018
    Posts:
    6