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

How to handle sprite pivot when I use Sprite Atlas?

Discussion in '2D' started by oharinth, Jan 25, 2020.

  1. oharinth

    oharinth

    Joined:
    Jul 8, 2015
    Posts:
    25
    Dear unity developer,

    Usually I handle each sprite pivot using Sprite Editor.
    But, If I use Sprite Altas( new feature on 2018 version) , I can't find how to handle each sprite image's pivot.
    I wish your good answer.

    Jason
     
  2. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,260
    Sprite Atlas doesn't require you to do anything different with the individual sprites. Setup the pivots and any other setting like normal, then the system will automatically setup the atlas when you press play or build the player.
     
    oharinth likes this.
  3. oharinth

    oharinth

    Joined:
    Jul 8, 2015
    Posts:
    25
    In Sprite Editor, I can setup pivot position of each sprite to move center of rotation manually.
    But, as you said, if Sprite Atlas automatically setup them, how can I setup each invidividual sprite pivot manually?
     
  4. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,260
    It generates the atlas using the settings you setup in the individual sprites.
     
    oharinth likes this.
  5. oharinth

    oharinth

    Joined:
    Jul 8, 2015
    Posts:
    25
    Thank you for your kind answer.
     
    Chris-Trueman likes this.
  6. oharinth

    oharinth

    Joined:
    Jul 8, 2015
    Posts:
    25
    I tested it. I setup pivot to each individual sprite images with Sprite Editor. Then I packed them with Sprite Atlas.
    Result is bad. Draw call(number of Batches) on Stats in Game View is same as number of each sprites.
    So I can't find how to edit pivot of Sprite Atlas.
    How can I edit pivot of each sprite in Sprite Atlas?
     
  7. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    These are two very different things we're talking about.

    You don't edit individual sprites in the SpriteAtlas. The SpriteAtlas is just a container. It holds all the Sprite data from your individual sprites, and knows where in the spritesheet they are packed. When you change an individual sprite, that data will be packed into the SpriteAtlas when you build the game. So edit your individual sprites as usual, use them as usual, and at runtime the major difference is that they will render using a single texture for all the sprites in the atlas.

    As for why your sprites aren't batching, it could be a number of reasons, so try using the Frame Debugger to see why your sprites aren't batching. Window > Analysis > Frame Debugger
     
    Last edited: Jan 27, 2020
    oharinth and eses like this.
  8. oharinth

    oharinth

    Joined:
    Jul 8, 2015
    Posts:
    25
    Thank you for your answer.
    At first, In my example, I tested about batching.
    I made 10 each single sprites. And they have 10 each single sprite sheet and pivot information(not packed to one spritesheet). and I placed them in Game View. At runtime, It was 10 Batches.
    And I packed them with Sprite Atlas, It was still 10 Batches(draw calls). So result was bad.
    And I packed them with one old type spritesheet, It was 1 Batche. Result was good. But it was not using Sprite Atals.
    You said edit my individual sprites as usual. But, how can I edit individual sprites? Usually I edit my spritesheet with Sprite Editor and I setup pivot and physics rectangle with Sprite Editor. Without Sprite Editor, How can I setup pivot and physics rectangle?
    So far, the things I found is we cannot setup pivot and physics rectangle with Sprite Atlas. Sprite Atlas was just a container but not editable to each sprite pivot.
    Is there any good solution?
     
  9. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    The SpriteEditor is still available for every Sprite in your project. Whether you import 100 separate images, or 1 image containing 100 sliced out sprites, you can still use the SpriteEditor to set their pivot points, or even set it in the inspector. They can all be packed using SpriteAtlas.

    Capture.PNG

    Make sure that you have SpritePacker settings set to "Always Enabled" to use the atlas it in play mode.
    Capture2.PNG
    https://docs.unity3d.com/Manual/SpritePackerModes.html
     
    oharinth likes this.
  10. oharinth

    oharinth

    Joined:
    Jul 8, 2015
    Posts:
    25
    Thank you LiterallyJeff,

    I tested like you said. And I could setup pivot and and physics rectangle for each sprite with Sprite Editor.
    And I packed them with Sprite Atlas. And I found the Batches(draw call) are just 1 at runtime. Everythings works well!
    You're totally correct.
    I really thank you for your kind answer.


    Jason
     
    Last edited: Jan 28, 2020
    LiterallyJeff likes this.