Search Unity

Prefab Preview Image With Custom Shader

Discussion in 'Prefabs' started by TinyTitanDave, Jan 8, 2020.

  1. TinyTitanDave

    TinyTitanDave

    Joined:
    Jan 9, 2017
    Posts:
    8
    I'm currently having an issue with some of our prefabs preview images when viewing it in the Project tab/window.

    Our shader is doing a palette swap. The shader uses _MainTex as a lookup for a palette color index, then samples into a palette texture with all the colors based on the lookup, then uses an offset for different variations. The lookup texture (_MainTex), palette texture and palette row are all serialized on the game object, but it seems like when the preview image is generated, the palette texture and palette row are not set (or set to some defaults, like a single white pixel and 0)

    As a test, I returned red from the pixel shader, made a modification to our prefab, hit ctrl+s to save, and it regenerated the preview image with all red sprites. Then I returned the pixel from our lookup texture and saved, and the prefab preview image showed all the sprites with the lookup textures. After it sampled into our palette texture, all the sprites were white. So the shader is executing.

    I tried overriding Awake, OnEnable, OnPreRender, OnPreCull, OnBecameVisible, etc, and a few other ones within our C# script and called our function to apply the material property block, but that had no affect.

    Is there some other function/callback that I can hook into to apply out material property block before the preview image is generated? Or is there something else going?

    Any help would be appreciated.

    Edit: I'm not sure if this is the correct section to post in.