Search Unity

Bug Broken prefab thumbnail generator (2020.3.25f1)

Discussion in 'Editor & General Support' started by The-White-Guardian, Mar 7, 2022.

  1. The-White-Guardian

    The-White-Guardian

    Joined:
    May 16, 2019
    Posts:
    4
    Hi. I've been working with URP for quite some time now, and the sheer frustration that prefabs are giving me cannot be overstated. For some reason, when I attempt to import an Asset that was created with anything other than URP shaders, the materials show up as pink, and thus the prefabs show up as pink.

    This of course is not a surprise, the materials must be altered to support URP. So I update the materials to do just that. But then, for some reason, it becomes physically impossible to update the prefab thumbnail. Mind you, the prefab displays properly in the game view, the scene view, and the preview window. The thumbnail however remains wholly pink. I've tried literally everything.
    - Right click -> Refresh: no effect.
    - Right click -> Reimport: no effect.
    - Gear icon -> Reset: no effect.
    - Open prefab, add a cube child: main asset still shows up as pink in the thumbnail, cube renders correctly.

    After that I tried several scripting approaches:
    - Re-import selected assets through AssetDatabase.GetAssetPath and AssetDatabase.ImportAsset: no effect.
    - Force thumbnail refresh by changing all material slots to a blank material and then reverting the material assignment: thumbnail correctly updates to the blank materials, then reverts to the pink materials.
    - Export problematic assets as package, delete project assets, and import the package: no effect.

    At this point I've tried literally everything I could. I can only conclude that there is something with the materials that causes the thumbnail renderer to break, but not any other rendering environment.
     
  2. HarryCodder

    HarryCodder

    Joined:
    Feb 20, 2015
    Posts:
    84
    We just upgraded from Unity 2020.3.20 to Unity 2020.3.31 and some (a lot) of our assets also fails to render a preview texture now.

    I mean, isn't the whole point of the LTS branch to avoid this kind of time consuming problems?
    We've literally had problems every single time we upgrade.
    As a bonus fact, I've filed a bug for a regression touching that same preview system almost exactly one year ago and the bug still hasn't been fixed. Seriously, what's the point of the LTS branch if regression are not fixed within a full year.
    I'm just venting at this point but this is infuriating.

    Anyway, if you ever found a solution or a workaround to that problem, I'd be happy to hear about it.
     
  3. The-White-Guardian

    The-White-Guardian

    Joined:
    May 16, 2019
    Posts:
    4
    I have, actually. I've traced down the problem to materials. The materials that keep rendering pink in the preview are all materials that previously used a different shader. Examples are shaders made with Amplify Shader Editor, targeting Standard RP and not URP. I've found that swapping the shader to URP shaders, though this works in the game view, somehow breaks the preview renderer.

    I presume that this is because materials will still save properties for past assigned shaders, even if it isn't the shader that is currently in use. That is to say, if a material previously used a shader had a property '_MyProp', then swapping the shader of the material to Universal/Lit will result in '_MyProp' still being cached in the material. You can see this by swapping the Inspector to Debug view.

    What worked for me is an editor script that adds a menu command. This command loops over all materials in the selection and then, for each material, using SerializedObjects, gets the dictionaries of saved material properties, as a SerializedProperty. It then deletes every cached property that isn't a property of the currently targeted shader, effectively pruning the material to just those properties that the targeted shader is using. After that, forcing a repaint by doing stuff like
    • Changing the transform position of the prefab;
    • Reimporting the prefab;
    • Resetting the prefab
    Seems to work again. No idea what cached properties are breaking the preview renderer, or why, but that was the problem in my case at least.
     
    HarryCodder likes this.
  4. HarryCodder

    HarryCodder

    Joined:
    Feb 20, 2015
    Posts:
    84
    Hi !
    Thanks a lot for responding, we already have a command to cleanup cached properties in materials, I'm going to poke around that and see what happens.