Sprite Swap overview (Experimental Feature) | 2D Animation | 4.1.1
docs.unity3d.com
    Show / Hide Table of Contents

    Sprite Swap overview (Experimental Feature)

    Sprite Swap is an experimental feature that enables you to change a GameObject’s rendered Sprite within the same character Prefab. This enables you to quickly and easily create multiple characters that look different while reusing existing bone and Mesh data. You can also use Sprite Swap to switch the displayed Sprite on each frame at run time to create frame-by-frame animation.

    The workflow for implementing Sprite Swap differs if you are using the workflow that is integrated with 2D Animation, or if you are manually setting up the Sprite Swap components.

    Sprite Swap Assets and components

    The following Assets and components are part of the Sprite Swap process:

    1. The Sprite Library Asset contains the Categories and Labels of the Sprites.
    2. The Sprite Library component shows the currently referred to Sprite Library Asset.
    3. The Sprite Resolver component is used to request a Sprite registered to the Sprite Library Asset by referring to the Category and Label value of the desired Sprite.

    How Unity generates Sprite Swap Assets and components

    Unity generates the various Sprite Swap components in the following steps:

    1. When you import a .psb file with the PSD Importer, Unity generates a Prefab containing a Sprite for each Layer in the source file.

    2. If you create any Categories or Labels while editing the character Prefab, Unity automatically generates a Sprite Library Asset as a sub-Asset of the Prefab.

    3. When the Prefab is brought into the Scene view, Unity generates a GameObject for each Sprite in the Prefab that does not belong to a Category. However if the Sprite is the first Label in a Category, then Unity will generate a GameObject for the Sprite as well.

    4. If the Prefab has a Sprite Library Asset sub-Asset, then Unity attaches the Sprite Library component to the root GameObject which is set to reference the Sprite Library Asset created in step 1 by default.

    5. Unity attaches the Sprite Resolver component to all Sprite GameObjects that belong to a Category.

    Refer to the respective component pages for more information on their functions and properties.

    Sprite Swap and 2D Animation integration

    Sprite Swap is integrated with the 2D Animation workflow. You must install the following packages or newer to use the Sprite Swap feature:

    • 2D Animation version 2.2.0-preview.1
    • PSDImporter version 1.2.0-preview.1

    Skeletal animation limitations

    To ensure Sprite Swap works correctly with skeletal animation, the skeleton must be identical between the Sprites being swapped. Use the Copy and Paste tools to duplicate the skeleton rig from one Sprite to the other Sprite(s) to ensure they can be swapped smoothly.

    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023