Mecanim sprite sheet animation UV



  • Hello,

    I have been trying to understand how to scale a secondary image properly whenever you use a Sprite Sheet animation from mecanim in a SpriteRenderer.

    In my example I want to render a fire effect over my character sprite. The animation of the main texture of the sprite is managed by an animator. My problem is that the fire effect looks like it is scaled to the size of the full sprite sheet of the animation, not as the current frame as I would like.
    Is there a way to get the proper UV comming from sprite sheet animations managed by mecanim ?

    0_1517643505322_shaderoIssue.png



  • The big problem with Texture Atlas is that Unity doesn't allow to specify the good UV coordonate within the shader.

    They are an alternative way to use sprite sheet.

    For example, if we use this sprite sheet ( 512x512 )

    0_1517736924727_977588b4-9dda-46d5-bfe6-3a4b2a4bccf7-image.png

    And use the MainTexture, it would do exactly the same as your example.

    But, if we use NewTexture instead, you can manipulate the whole texture as a single sprite.

    0_1517737190926_db31c682-5d08-4b4c-9f49-ceb495c70f76-image.png

    0_1517737146657_ad024d41-1e3e-4529-b7de-d8de630f81ab-image.png

    Than, for use with Mecanim,
    use this line, on the material parameter Sprite Sheet Frame UV, you won't see the sprite as a standard texture atlas, but's it's work

    0_1517737515451_514f8c18-c7bb-4762-93d4-938d27e77c8a-image.png

    Don't forget to turn the key on constant like this

    0_1517737629436_8f62c088-9a7f-4c1e-8301-66ca31e25d76-image.png

    It's a strange manipulation but for the moment, since Unity doesn't allow to do that directly by shader, it's the only way, but it's work great as you can see.

    Hope it's help,
    If you have any other questions, don't hesitate.



  • Hello,

    Thank you for the clear example. This is exactly what I wanted to do.
    So it is how I feared ... I will have to reimport all my animations using your trick.

    Well if Unity adds a way to use proper UV, having a source component using it in Shadero would be a great addition :-)
    Keep up the good work! Your product is great!


 

Looks like your connection to Vetasoft Assets was lost, please wait while we try to reconnect.