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

Trying to animate an Image component material/shader

Discussion in 'UGUI & TextMesh Pro' started by IntDev, Aug 27, 2014.

  1. IntDev

    IntDev

    Joined:
    Jan 14, 2013
    Posts:
    152
    I have a material with a wipe transition shader. In that shader I have a custom property _blendPos that I use to move the shader effect, like this:

    Code (csharp):
    1. my2dSprite.renderer.sharedMaterial.SetFloat("_blendPos", value);
    It works fine on a 2D Sprite.

    But if i try to assign the same shader/material to an Image component, it doesn't work:

    Code (csharp):
    1. // Start()
    2. myImageMaterial = GetComponent<Image>().material;
    3. // Update ()
    4. myImageMaterial.SetFloat("_blendPos", value);
    I can see the material being updated in the "Project View". But nothing happens in the "Game/Scene View".

    Help.
     
    Last edited: Aug 27, 2014
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,183
    In the UI the used material isn't always the one set in the inspector (we duplicate materials internally for things like stenciling ect). Could you raise a bug on this so we can figure out a way forward to help make this work? You can probably use Shader.SetKeyword on the global scale for the moment, but it's not the best solution going forward.
     
  3. IntDev

    IntDev

    Joined:
    Jan 14, 2013
    Posts:
    152
    @Tim C Actually, the Image component I was using had a Mask component on it. When I removed it my shader/material worked. Then it's something related to the Mask component. So in my specific case I think it's not a bug. But maybe that could work in a mask too, say, to have a mask animation, or just as an effect on the mask's image. Do you want me to raise a bug on that anyway?
     
    Last edited: Aug 28, 2014
  4. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,183
    Please do, with a repro.
     
  5. IntDev

    IntDev

    Joined:
    Jan 14, 2013
    Posts:
    152
    Last edited: Aug 28, 2014
  6. vero_chan

    vero_chan

    Joined:
    Oct 29, 2013
    Posts:
    3
    Hi,

    I faced the same problem yesterday and I couldn't make it work using Unity 5.3.3, so I think the bug is still there, could you check it?

    As IntDev explained, I was trying to apply an animation to the material assigned to an Image component who had a UI Mask component on it. If the Image component was attached to the Mask it didn't work, if I removed the UI Mask the animation on the material of the Image component worked perfectly.

    In my case I took a roundabout and created a material using a shader with a Culling mask and the image to apply to the Culling mask, then applied it to the Image component in order to avoid using the UI Mask, this way the animation works perfectly.
     
  7. lassade

    lassade

    Joined:
    Jan 27, 2013
    Posts:
    127
    For anyone looking for an awnser on 2020.1.11f1 you need to use:
    Code (CSharp):
    1. image.materialForRendering
    Sorry for the necro;
     
    _eternal and ColonelKurt like this.