Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Material Inspector Preview Window doesn't animate?

Discussion in 'Editor & General Support' started by rgatts_wizards, Jul 23, 2020.

  1. rgatts_wizards

    rgatts_wizards

    Joined:
    Apr 2, 2020
    Posts:
    3
    Is there a project setting that makes this button actually show animated materials animating? What is the name of this part of the GUI even?
    upload_2020-7-23_13-17-36.png
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    3,364
    My animated materials animate fine when I press that. Does this material animate if you put it on an object and drop it into the scene view? (Assuming you've turned on Animated Materials in the Scene view...)
     
  3. rgatts_wizards

    rgatts_wizards

    Joined:
    Apr 2, 2020
    Posts:
    3
    Animated materials in scene view do draw correctly (as long as I have them turned on like you mentioned).
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    3,364
    How did you make the shader? Hand-written Cg/HLSL, or Shader Graph? What are you specifically using to animate this over time? _Time.y, the Shader Graph Time node? Care to share that specific code, so I can see if it animates for me as well?
     
  5. rgatts_wizards

    rgatts_wizards

    Joined:
    Apr 2, 2020
    Posts:
    3
    It's handwritten, time is modded by 1000 here so that it repeats every 1000 seconds and avoids some float precision problems that can pop up.
    upload_2020-7-28_9-52-16.png
     
  6. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    3,364
    Well, it works fine for me. I just created a standard unlit shader, and modified the UV to add _Time.y to it, and it animates fine both in the scene view and in the material preview inspector.

    Maybe try this in a brand new project, just creating this shader, assigning a material and texture to it, and see if the material animates?

    Code (CSharp):
    1. Shader "Unlit/DeleteMe2"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex("Texture", 2D) = "white" {}
    6.     }
    7.         SubShader
    8.     {
    9.         Tags { "RenderType" = "Opaque" }
    10.         LOD 100
    11.  
    12.         Pass
    13.         {
    14.             CGPROGRAM
    15.             #pragma vertex vert
    16.             #pragma fragment frag
    17.             // make fog work
    18.             #pragma multi_compile_fog
    19.  
    20.             #include "UnityCG.cginc"
    21.  
    22.             struct appdata
    23.             {
    24.                 float4 vertex : POSITION;
    25.                 float2 uv : TEXCOORD0;
    26.             };
    27.  
    28.             struct v2f
    29.             {
    30.                 float2 uv : TEXCOORD0;
    31.                 UNITY_FOG_COORDS(1)
    32.                 float4 vertex : SV_POSITION;
    33.             };
    34.  
    35.             sampler2D _MainTex;
    36.             float4 _MainTex_ST;
    37.  
    38.             v2f vert(appdata v)
    39.             {
    40.                 v2f o;
    41.                 o.vertex = UnityObjectToClipPos(v.vertex);
    42.                 o.uv = TRANSFORM_TEX(v.uv + float2(_Time.y, _Time.y), _MainTex);
    43.                 UNITY_TRANSFER_FOG(o,o.vertex);
    44.                 return o;
    45.             }
    46.  
    47.             fixed4 frag(v2f i) : SV_Target
    48.             {
    49.                 // sample the texture
    50.                 fixed4 col = tex2D(_MainTex, i.uv);
    51.             // apply fog
    52.             UNITY_APPLY_FOG(i.fogCoord, col);
    53.             return col;
    54.         }
    55.         ENDCG
    56.     }
    57.     }
    58. }
    59.  
     
unityunity