Master Sprites
A Master Sprite is a template for a sprite that contains all the necessary data for animation. All sprites, whether scene objects or prefabs, must reference a Master Sprite from which they will load their data on Awake().
Static or Animated
Master Sprites can be static or animated. Static sprites have no animation and consist of a single frame. You can use static sprites for non-animated background elements, for example. Static sprites are faster than animated sprites, so if you have a sprite with only one frame, make it a static sprite. Note that you will almost always want to assign static sprites to groups as a static sprite outside a group would generate an atlas with only one frame wasting memory. See Using the Editor - Sprite Properties for how to set this property.
Texture Atlasing
Texture atlases are generated automatically for every Master Sprite.
Atlases will be created on save if animations and frames are defined.
- There is no limit to the number of atlases for each Master Sprite -- the more frames you add, the more atlases will be created as necessary. (The Max Atlas Size setting in Editor Properties will also affect how many atlases each sprite needs.)
- There is no limit to the number of frames each animation can have. Animations can span atlases with no issues, maintaining high performance because child planes are created for each atlas and are enabled and disabled as needed during playback. This is vastly faster than swapping materials on a single plane.
- Source images can be of any aspect ratio, can be non power of 2, and don't have to be pre-aligned.
- Source images with blank space around the edges will be trimmed by default, saving texture space and memory.
- If the same source image is used multiple times in an animation or among different animations, the image will only appear once in the atlas.
- Similarly, if the source image is used among multiple Master Sprites in a Sprite Group, the image will only appear once in the atlas.
- Master Sprites outside groups have certain customizable atlas settings. See Using the Editor - More Sprite Settings for more information. Master Sprites in groups also have these settings, but they are shared among the group. See Using the Editor - Shared Group Properties for more information.
- See Using the Editor - Editor Properties for global atlas settings.
Sprite Groups
A Master Sprite can exist as an independent sprite with its own private atlases, or as a member of a Sprite Group and share atlases and materials with other Master Sprites to save memory and draw calls. See Sprite Groups for more information.
Colliders
Define any number of static or animated box colliders in the sprite. This collider system provides an easy way to add colliders that match the animation of your sprites. See Colliders for more information.
Locators
Define any number of locators, which is an animatable transform on a sprite which can be used for attaching objects or as an origin point for spawning objects. See Locators for more information.
Material Sets
If you need to swap materials on a sprite for any reason (effects, etc.), material sets allow you to create any number of materials and swap them on the fly without incurring excess draw calls. See Material Sets for more information.
Mesh Types
Sprites can use a standard rectangular mesh or an automatically-generated mesh shaped to fit the sprite to reduce overdraw. You can customize the mesh type and mesh generation settings globally and for each sprite individually
How Master Sprites Work
When a Sprite is instantiated, the animation data is loaded from its Master Sprite. This has some useful implications:
- Complex hierarchies just work. Sprite components can be nested in complex hierarchies or parented to other objects without any issues when making changes to the master.
- Prefabs and non-prefabs work equally well. It is recommend you use prefabs where possible, but you can certainly create non-prefab Sprites in-scene if you choose without worrying about whether they'll be updated when you make a change to the master.
- Sprites are completely reusable. You can have Sprite components based on the same Master Sprite in as many different prefabs or scene sprites as you like. When a change is made to the master, all the children will automatically have the lastest data.
- Nothing in the scene or prefab sprites needs to be updated every time you make a change in the source Master Sprite.
- Updating Master Sprites is fast because there is no searching for Sprite components on prefabs or scene objects to push updates to.
Because of this system, there are a few things to be aware of during development:
- Game Master Sprites must be inlcuded in the build. This should happen automatically in most situations since each Sprite in scene contains an object reference to its Master Sprite. If for any reason you need to manually manage these files, they are located in the "Assets/Sprite Factory/SaveData/MasterSprites/Game" folder. (Just as a note, Editor Master Sprites contain un-atlased source image data and are never referenced or loaded except by the editor, therefore they do not take up any memory in-game and should not be included in a build.)
- Deleting a Master Sprite in the editor will cause all sprites in scene or in prefabs based on that Master Sprite to break because they cannot refer back to their template. These sprites can be assigned a different Master Sprite with the "Assign Master Sprite to Selected Object" command in the editor. Broken sprites in scene will be deactivated on play.
- Even though it may take more processing time to load the data on instantiation compared to serializing the data in each prefab, the amount of data loaded is quite small.
Creating a Master Sprite
Master Sprites are created and managed in the Sprite Factory editor window. See Using the Editor - Master Sprites for more information.