Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Optimize generated textures in runtime?

Discussion in '2D' started by gresternandes, Jun 16, 2022.

  1. gresternandes

    gresternandes

    Joined:
    Feb 4, 2021
    Posts:
    2
    Hello, first of all I'm new to unity and I heard some concepts that I don't know if could be applied to my actual problem.
    I'm generating textures (png for now) on runtime and I'm wondering if I could package or tile them in a way that could be beneficial to Unity.
    They are rather tiny textures 16x8 but they are 40 and all used constantly in the same context. So I was wondering if after generating them, I could make use of Tilemaps for some sort of benefit regarding the issue of draw calls (or other problems I'm unaware). From my understanding, Tilepalletes and Tile Atlas are all used exclusively in editor/inspector (or at least I couldn't find the underlying code for either case.) Or perhaps if simply generating them straight to DXT, would be enough to satisfy engine needs since they are so tiny.

    Thanks!
    (On second thought perhaps I should have created this thread in another category.)
     
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,503
    To make use of them in a tilemap, you'd need to create sprites. The method for this is Sprite.Create(). Then you'd either want to dynamically create tiles or replace the default sprites in existing tiles.

    The benefit should be comparable to a spritesheet or Sprite Atlas, mainly that you'd have fewer batches. You're correct in your understanding that Sprite Atlas doesn't allow runtime generation.
     
    gresternandes likes this.
  3. gresternandes

    gresternandes

    Joined:
    Feb 4, 2021
    Posts:
    2
    I'm thinking in the long run, and the uses I'll have for these textures will both be 2D for sprite-like and UI elements and possibly in 3D objects. In that case I'd have to create perhaps a 2D tilemap and a 3D tilemap. (I'm assuming the way either is built and its capabilities are oriented for 2D and 3D exclusively respectively). Given the diverse uses not sure if creating all these tilemaps will be worth it, or if just straight up use/load the Textures2D as they are needed.