Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Material broken after updating from 2019.1.0b3 to 2019.1.0f2

Discussion in 'Editor & General Support' started by icebear007, Apr 16, 2019.

  1. icebear007

    icebear007

    Joined:
    Jun 8, 2016
    Posts:
    67
    Hi,

    I'm running into an issue with my materials when I update my project from 2019.1.0b3 to 2019.1.0f2: they are missing the albedo texture and the color attribute is wrong as well. The materials are using the standard "Lightweight Render Pipeline/Lit" shader.

    Code (CSharp):
    1. %YAML 1.1
    2. %TAG !u! tag:unity3d.com,2011:
    3. --- !u!21 &2100000
    4. Material:
    5.   serializedVersion: 6
    6.   m_ObjectHideFlags: 0
    7.   m_CorrespondingSourceObject: {fileID: 0}
    8.   m_PrefabInstance: {fileID: 0}
    9.   m_PrefabAsset: {fileID: 0}
    10.   m_Name: acorn_mat
    11.   m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
    12.   m_ShaderKeywords:
    13.   m_LightmapFlags: 4
    14.   m_EnableInstancingVariants: 1
    15.   m_DoubleSidedGI: 0
    16.   m_CustomRenderQueue: -1
    17.   stringTagMap: {}
    18.   disabledShaderPasses: []
    19.   m_SavedProperties:
    20.     serializedVersion: 3
    21.     m_TexEnvs:
    22.     - _BumpMap:
    23.         m_Texture: {fileID: 0}
    24.         m_Scale: {x: 1, y: 1}
    25.         m_Offset: {x: 0, y: 0}
    26.     - _EmissionMap:
    27.         m_Texture: {fileID: 0}
    28.         m_Scale: {x: 1, y: 1}
    29.         m_Offset: {x: 0, y: 0}
    30.     - _MainTex:
    31.         m_Texture: {fileID: 2800000, guid: bb65d3758d81f9f4eb202e539110dd78, type: 3}
    32.         m_Scale: {x: 1, y: 1}
    33.         m_Offset: {x: 0, y: 0}
    34.     - _MetallicGlossMap:
    35.         m_Texture: {fileID: 0}
    36.         m_Scale: {x: 1, y: 1}
    37.         m_Offset: {x: 0, y: 0}
    38.     - _OcclusionMap:
    39.         m_Texture: {fileID: 0}
    40.         m_Scale: {x: 1, y: 1}
    41.         m_Offset: {x: 0, y: 0}
    42.     - _SpecGlossMap:
    43.         m_Texture: {fileID: 0}
    44.         m_Scale: {x: 1, y: 1}
    45.         m_Offset: {x: 0, y: 0}
    46.     m_Floats:
    47.     - _AlphaClip: 0
    48.     - _Blend: 0
    49.     - _BumpScale: 1
    50.     - _Cull: 2
    51.     - _Cutoff: 0.5
    52.     - _DstBlend: 0
    53.     - _EnvironmentReflections: 1
    54.     - _GlossMapScale: 1
    55.     - _Glossiness: 0.5
    56.     - _GlossyReflections: 1
    57.     - _Metallic: 0
    58.     - _OcclusionStrength: 1
    59.     - _QueueOffset: 0
    60.     - _ReceiveShadows: 1
    61.     - _Smoothness: 0.5
    62.     - _SmoothnessTextureChannel: 0
    63.     - _SpecularHighlights: 1
    64.     - _SrcBlend: 1
    65.     - _Surface: 0
    66.     - _WorkflowMode: 1
    67.     - _ZWrite: 1
    68.     m_Colors:
    69.     - _BaseColor: {r: 1, g: 1, b: 1, a: 1}
    70.     - _Color: {r: 1, g: 1, b: 1, a: 1}
    71.     - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
    72.     - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
    73.  

    Code (CSharp):
    1. %YAML 1.1
    2. %TAG !u! tag:unity3d.com,2011:
    3. --- !u!21 &2100000
    4. Material:
    5.   serializedVersion: 6
    6.   m_ObjectHideFlags: 0
    7.   m_CorrespondingSourceObject: {fileID: 0}
    8.   m_PrefabInstance: {fileID: 0}
    9.   m_PrefabAsset: {fileID: 0}
    10.   m_Name: acorn_mat
    11.   m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
    12.   m_ShaderKeywords:
    13.   m_LightmapFlags: 4
    14.   m_EnableInstancingVariants: 1
    15.   m_DoubleSidedGI: 0
    16.   m_CustomRenderQueue: 2050
    17.   stringTagMap:
    18.     RenderType: Opaque
    19.   disabledShaderPasses: []
    20.   m_SavedProperties:
    21.     serializedVersion: 3
    22.     m_TexEnvs:
    23.     - _BumpMap:
    24.         m_Texture: {fileID: 0}
    25.         m_Scale: {x: 1, y: 1}
    26.         m_Offset: {x: 0, y: 0}
    27.     - _EmissionMap:
    28.         m_Texture: {fileID: 0}
    29.         m_Scale: {x: 1, y: 1}
    30.         m_Offset: {x: 0, y: 0}
    31.     - _MainTex:
    32.         m_Texture: {fileID: 2800000, guid: bb65d3758d81f9f4eb202e539110dd78, type: 3}
    33.         m_Scale: {x: 1, y: 1}
    34.         m_Offset: {x: 0, y: 0}
    35.     - _MetallicGlossMap:
    36.         m_Texture: {fileID: 0}
    37.         m_Scale: {x: 1, y: 1}
    38.         m_Offset: {x: 0, y: 0}
    39.     - _OcclusionMap:
    40.         m_Texture: {fileID: 0}
    41.         m_Scale: {x: 1, y: 1}
    42.         m_Offset: {x: 0, y: 0}
    43.     - _SpecGlossMap:
    44.         m_Texture: {fileID: 0}
    45.         m_Scale: {x: 1, y: 1}
    46.         m_Offset: {x: 0, y: 0}
    47.     m_Floats:
    48.     - _AlphaClip: 0
    49.     - _Blend: 0
    50.     - _BumpScale: 1
    51.     - _Cull: 2
    52.     - _Cutoff: 0.5
    53.     - _DstBlend: 0
    54.     - _GlossMapScale: 1
    55.     - _Glossiness: 0.5
    56.     - _GlossyReflections: 1
    57.     - _Metallic: 0
    58.     - _OcclusionStrength: 1
    59.     - _ReceiveShadows: 1
    60.     - _SmoothnessTextureChannel: 0
    61.     - _SpecularHighlights: 1
    62.     - _SrcBlend: 1
    63.     - _Surface: 0
    64.     - _WorkflowMode: 1
    65.     - _ZWrite: 1
    66.     m_Colors:
    67.     - _Color: {r: 1, g: 1, b: 1, a: 1}
    68.     - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
    69.     - _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
    70.  

    When you compare the old and new materials, these are the new entries while nothing got deleted:
    Code (CSharp):
    1.  
    2.     - _BaseMap:
    3.         m_Texture: {fileID: 2800000, guid: bb65d3758d81f9f4eb202e539110dd78, type: 3}
    4.         m_Scale: {x: 1, y: 1}
    5.         m_Offset: {x: 0, y: 0}
    6.     - _EnvironmentReflections: 1
    7.     - _QueueOffset: 0
    8.     - _Smoothness: 0.5
    9.     - _BaseColor: {r: 1, g: 1, b: 1, a: 1}
    10.  
    It seems the names have just changed and Unity doesn't doesn't convert them? For example, the texture is now part of _BaseMap and before it was part of _MainTex.

    Thanks,
    Alex
     
    Last edited: Apr 27, 2019
  2. EcoCricket

    EcoCricket

    Unity Technologies

    Joined:
    Mar 24, 2017
    Posts:
    1
  3. SmartCarrion

    SmartCarrion

    Joined:
    Jul 27, 2013
    Posts:
    27
    I've got this happening too, coming from 2018.3.12 to 2019.1.0f2. Basically, every material in my project is destroyed.

    I guess our workaround is to roll back to the old version for now and wait for a bug fix? Thanks for inputting the bug, I voted it up.
     
  4. icebear007

    icebear007

    Joined:
    Jun 8, 2016
    Posts:
    67
    If it doesn't get resolved soon, I'll create a simple, hacky script to do the conversion offline (assuming ascii material files).
     
  5. Andre_Mcgrail

    Andre_Mcgrail

    Unity Technologies

    Joined:
    Dec 9, 2016
    Posts:
    244
    Hey,

    Just saw this, but we indeed have an upgrader for this, and it just doesn't get kicked off as expected, we have it as a improvement to make sure it kicks off when upgrading from an earlier package. This reply to the LWRP thread explains in more detail LWRP: 4.6.0-preview (18.3) & 5.2.1 (19.1) are out

     
  6. icebear007

    icebear007

    Joined:
    Jun 8, 2016
    Posts:
    67
    Thanks @Andre_Mcgrail , I tried to reimport my materials (LWRP/Lit) but the issue remains. Is there another way to trigger the upgrader?
     
  7. icebear007

    icebear007

    Joined:
    Jun 8, 2016
    Posts:
    67
    @Andre_Mcgrail , I tried reimport more materials. A bit more happened but it's still not really working:

    1) Some materials get fixed (2 out of 50) but the majority is still broken.
    2) For some materials I get a debug log (3 out of 50) though they aren't the materials which got fixed.

    Code (csharp):
    1.  
    2. LWRP Material log:
    3. football_mat initialized. upgrading:v0 to v1
    4. UnityEditor.AssetPostprocessingInternal:PostprocessAllAssets(String[], String[], String[], String[], String[])
    5.  
    3) Checking the git diff, the upgrader might process all(?) of the materials but doesn't necessarily fix them:
    Code (csharp):
    1.  
    2.      - _MainTex:
    3. -        m_Texture: {fileID: 2800000, guid: f31b2ebf9418acd44bd267cff48507f8, type: 3}
    4. +        m_Texture: {fileID: 0}
    5.  
    Here the texture reference got deleted although the texture with the guid f31b2ebf9418acd44bd267cff48507f8 still exists! So be careful when reimporting materials! Luckily I can roll back all those materials.
     
    Last edited: Apr 24, 2019
  8. icebear007

    icebear007

    Joined:
    Jun 8, 2016
    Posts:
    67
    I wrote a simple python script to fix the materials for me. It did the job for me so it might help others but be careful. It's not very pretty, it doesn't create backups and it's not fail safe so use with caution. git is your friend!

    - Copy MainTex to BaseMap
    - Copy Color to BaseColor
    - Add QueueOffset
    - Add Smoothness
    - Add EnvironmentReflections

    Code (CSharp):
    1.  
    2. from __future__ import print_function
    3.  
    4. import argparse
    5. import os
    6. import pprint
    7. from shutil import copyfile
    8. import io
    9.  
    10.  
    11. class MaterialFixer(object):
    12.  
    13.     def __init__(self):
    14.         self._filePaths = []
    15.         self._directories = []
    16.         self._logProcessedDirectories = set()
    17.         self._logInvalidDirectories = set()
    18.         self._logInvalidFiles = set()
    19.         self._logConvertedFiles = set()
    20.         self._logNothingToDoFiles = set()
    21.  
    22.         self._parseArgs()
    23.  
    24.     def _parseArgs(self):
    25.         parser = argparse.ArgumentParser()
    26.         parser.add_argument(
    27.             "-d",
    28.             "--directory",
    29.             nargs='*',
    30.             help="Convert all materials in directory")
    31.         parser.add_argument(
    32.             "-f",
    33.             "--file",
    34.             nargs='*',
    35.             help="Convert given material")
    36.         args = parser.parse_args()
    37.  
    38.         if args.file:
    39.             self._filePaths = args.file if isinstance(args.file, list) else [args.file]
    40.  
    41.         if args.directory:
    42.             self._directories = args.directory if isinstance(args.directory, list) else [args.directory]
    43.  
    44.     def run(self):
    45.         for filePath in self._filePaths:
    46.             self._convertFile(filePath)
    47.  
    48.         for directory in self._directories:
    49.             self._processDirectory(directory)
    50.  
    51.         self._printLog()
    52.    
    53.     def _printLog(self):
    54.         print("Processed directories: ")
    55.         pprint.pprint(self._logProcessedDirectories)
    56.         print("Converted files: ")
    57.         pprint.pprint(self._logConvertedFiles)
    58.         print("Already converted files: ")
    59.         pprint.pprint(self._logNothingToDoFiles)
    60.         print("Invalid directories: ")
    61.         pprint.pprint(self._logInvalidDirectories)
    62.         print("Invalid files: ")
    63.         pprint.pprint(self._logInvalidFiles)
    64.        
    65.     def _processDirectory(self, directory):
    66.         if not directory:
    67.             return
    68.  
    69.         if (not os.path.isdir(directory) or
    70.            not os.path.exists(directory)):
    71.             self._logInvalidDirectories.add(directory)
    72.             return
    73.  
    74.         self._logProcessedDirectories.add(directory)
    75.         for root, dirs, files in os.walk(directory):
    76.             self._logProcessedDirectories.add(root)
    77.             for filename in files:
    78.                 if os.path.splitext(filename)[1] == (".mat"):
    79.                     materialFile = os.path.join(root, filename)
    80.                     self._convertFile(materialFile)
    81.  
    82.     def _convertFile(self, filePath):
    83.         if not filePath:
    84.             return
    85.  
    86.         if not self._isValidFile(filePath):
    87.             self._logInvalidFiles.add(filePath)
    88.             return
    89.  
    90.         f = io.open(filePath, 'r', newline='\n')
    91.         lines = [line for line in f]
    92.         f.close()
    93.  
    94.         line_count = len(lines)
    95.         lines = self._processMainTex(lines)
    96.         lines = self._processEnvironmentReflections(lines)
    97.         lines = self._processQueueOffset(lines)
    98.         lines = self._processSmoothness(lines)
    99.         lines = self._processBaseColor(lines)
    100.  
    101.         if len(lines) != line_count:
    102.             self._logConvertedFiles.add(filePath)
    103.  
    104.             new_f = io.open(filePath, 'w', newline='\n')
    105.             new_f.writelines(lines)
    106.         else:
    107.             self._logNothingToDoFiles.add(filePath)
    108.  
    109.     def _processMainTex(self, lines):
    110.         mainTexIdx = -1
    111.         for idx, line in enumerate(lines):
    112.             if line.startswith("    - _BaseMap:"):
    113.                 return lines
    114.  
    115.             if line.startswith("    - _MainTex:"):
    116.                 mainTexIdx = idx
    117.        
    118.         if mainTexIdx == -1:
    119.             return lines
    120.        
    121.         texture_entry = lines[mainTexIdx + 1]
    122.         scale_entry = lines[mainTexIdx + 2]
    123.         offset_entry = lines[mainTexIdx + 3]
    124.  
    125.         lines.insert(mainTexIdx, offset_entry)
    126.         lines.insert(mainTexIdx, scale_entry)
    127.         lines.insert(mainTexIdx, texture_entry)
    128.         lines.insert(mainTexIdx, u"    - _BaseMap:\n")
    129.  
    130.         return lines
    131.  
    132.     def _processEnvironmentReflections(self, lines):
    133.         floatsIdx = -1
    134.         for idx, line in enumerate(lines):
    135.             if line.startswith("    - _EnvironmentReflections:"):
    136.                 return lines
    137.  
    138.             if line.startswith("    m_Floats:"):
    139.                 floatsIdx = idx
    140.        
    141.         lines.insert(floatsIdx + 1, u"    - _EnvironmentReflections: 1\n")
    142.         return lines
    143.  
    144.     def _processSmoothness(self, lines):
    145.         floatsIdx = -1
    146.         for idx, line in enumerate(lines):
    147.             if line.startswith("    - _Smoothness:"):
    148.                 return lines
    149.  
    150.             if line.startswith("    m_Floats:"):
    151.                 floatsIdx = idx
    152.        
    153.         lines.insert(floatsIdx + 1, u"    - _Smoothness: 0.5\n")
    154.         return lines
    155.  
    156.     def _processQueueOffset(self, lines):
    157.         floatsIdx = -1
    158.         for idx, line in enumerate(lines):
    159.             if line.startswith("    - _QueueOffset:"):
    160.                 return lines
    161.  
    162.             if line.startswith("    m_Floats:"):
    163.                 floatsIdx = idx
    164.        
    165.         lines.insert(floatsIdx + 1, u"    - _QueueOffset: 0\n")
    166.         return lines
    167.  
    168.     def _processBaseColor(self, lines):
    169.         colorLineIdx = -1
    170.         colorLine = ""
    171.         for idx, line in enumerate(lines):
    172.             if line.startswith("    - _BaseColor:"):
    173.                 return lines
    174.  
    175.             if line.startswith("    - _Color:"):
    176.                 colorLine = line
    177.                 colorLineIdx = idx
    178.        
    179.         lines.insert(idx, colorLine.replace("_Color", "_BaseColor"))
    180.         return lines
    181.  
    182.     @staticmethod
    183.     def _isValidFile(filePath):
    184.         if (not os.path.exists(filePath) or
    185.            not os.path.isfile(filePath)):
    186.             return False
    187.  
    188.         return os.path.splitext(filePath)[1] == ".mat"
    189.  
    190. if __name__ == "__main__":
    191.     MaterialFixer().run()
    192.  

    Alex