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.

Question 2D Sprite Animation using Texture2DArray

Discussion in 'General Graphics' started by charleshendry, May 30, 2022.

  1. charleshendry

    charleshendry

    Joined:
    Jan 7, 2018
    Posts:
    94
    Hi,

    I'm working on a project using 2D sprites using DOTS. Currently I'm using Texture2DArrays for everything. I think I'll be able to create everything with maybe 6 different sprite sizes, so that would render thousands of sprites with only 6 materials. I have procedurally generated terrain, characters and objects etc. and all working well so far.

    I'm now looking into sprite animations. As there aren't any 2D sprite animation tools yet for DOTS, I'm thinking of sticking with the Texture2DArrays rather than using sprite sheets, which I think is still way more commonly used. I'd be able to define start and end texture array indices for different animations and then send instructions to the shader to switch between the sprites to play the animation.

    I don't really see any issues, but AFAIK, Texture2DArrays aren't typically used for this, but maybe just because of the limitation on all sprites being the same size? Appreciate any comments or advice people have on this. Thanks.
     
  2. charleshendry

    charleshendry

    Joined:
    Jan 7, 2018
    Posts:
    94
  3. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,442
    charleshendry likes this.
  4. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    330
    IIRC, texture arrays can only be created at run-time in Unity. There is no file format that would import as a texture array. Maybe you could write a tool which saves them as an asset file but I don't think there is anything out of the box.
    Correction: There are flipbook textures which become a texture array, it seems.

    Another problem is, that you get a hitch when you create a texture array. So you'd have to create them on the loading screen where it doesn't matter that much.

    In addition to that, texture arrays don't support texture streaming and texture degradation.

    As you said, all sprites would have to have the same size but on the plus side, you don't have to do u/v calculations and the wrap/repeat filter would work.
     
    Last edited: Mar 1, 2023
    charleshendry likes this.
  5. charleshendry

    charleshendry

    Joined:
    Jan 7, 2018
    Posts:
    94
    Ok thanks. I already had an editor script that creates Texture2D assets and I can get animations and everything working well so far. So it sounds like it would work ok, I'll see if I run into any performance issues later on on a larger scale. I knew they could do mip maps, but didn't know about texture streaming, thanks.
     
  6. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    330
    I'd say, if you are fine with those limitations, you can use them - especially since flipbooks are imported as texture arrays anyways. Small disclaimer, though, I have no experience with flipbooks, just with texture arrays in general.
     
    charleshendry likes this.