Auto Trim for SpriteFrame
Once a texture is imported, the SpriteFrame asset generated with the texture will be trimmed automatically. Any fully transparent pixels around the image will be cropped. This will help us get the exact node size we need for Sprites.
When the SpriteFrame is auto-trimmed, the auto-trimmed information in the image below is grayed out and cannot be modified:
Trim Related Properties in Sprite Component
There are two properties related to trim setting in Sprite component:
TrimIf checked, the node's bounding box will not include transparent pixels around the image. Instead the bounding box will be an exact fit to trimmed image. If unchecked the bounding box will be showing original texture including transparent pixels.
Size ModeUse the options in this property to set node's size to the original texture size or trimmed image size. Options are:
TRIMMEDSelect this option will set the
sizeof the node to use trimmed image size of the current SpriteFrame used by Sprite component.
RAWSelect this option will set the size of the node to use the original texture size, including transparent pixels.
CUSTOMThis option make sure the size of the node will not be changed along with SpriteFrame, and should be managed by yourself. If you use the Rect Transform Tool to drag and change the
sizeof the node, or modify the
sizeproperty in Inspector panel, or modify the
heightin the script, the
Size Modeproperty will be automatically set to
The following picture shows the comparison of two size modes:
Sprite Animation with offset
There are a lot of animator prefer to draw the moving motion in texture, commonly seen in attack animations. Usually animator will use a large texture and put character on different positions on the texture for different animation frames. In this case, we need to set the Sprite component's
Trim property to
false, and set the
Size Mode to
RAW. In this way, the animation will use the original texture size when playing each sequence frame, and retain the information of transparent pixels around the image. So that the character's position drawn in the texture can be displayed correctly.
Trim property is set to
true, it is more suitable for animation where the displacement is completely controlled by the character's
We recommend users to use sprite sheet tools such as TexturePacker for generating sprite animation texture assets. In TexturePacker before you publish your sprite sheet, please make sure you choose
Trim in Trim Mode setting of Sprites section. Please do not use
Crop, flush position, or the trim information will be lost and you can't get back originial texture offset anymore. It is currently recommended to use version 4.x or higher for packaging to prevent the import failure caused by inconsistent export data in the lower version.