Sprite Factory

ReadMe
Release Notes
Overview
Using the Editor
Upgrading

Concepts
Sprites
Master Sprites
Sprite Groups
Colliders
Locators
Material Sets
SpriteUpdater
SpriteCamera

Advanced
Working in Multiple Projects

Classes
Runtime Classes

Videos
Overview
Creating Sprites
Sprite Inspector
Frame Events
Collision System
Locator System
Material Sets

Links
Sprite Factory Site
Web Documentation
Support
Contact

Material Sets

Material Set Editor

Material Sets allow you to define multiple materials for a sprite. You can switch a sprite's material at any time by changing the currently used material set via scripting. This can be useful for effects that require a different shader.

Creating Material Sets
Material Sets are created in the editor under the Sprite Properties of a Master Sprite. If the Master Sprite is in a Sprite Group, the material sets are created in the Sprite Group Properties instead of in the Master Sprite as they are shared among all sprites in the group.

How Material Sets Work
A Material Set requires a source material from which it will create materials for the sprite inheriting the source material's shader and settings. The source material's shader must have a _MainTex property. When a Master Sprite or Sprite Group is saved and atlases are created, one material will be created on disk for each atlas per material set. If you have a Master Sprite with 2 atlases and 3 material sets, a total of 6 materials will be created on disk.

Note: It's important that the source materials are never deleted from your project because it is used every time you make changes to the sprite/group. If you make changes to the source material later, in order for sprite materials to inherit the new material settings, you must update sprite materials by rebuilding the materials by either rebuilding the Master Sprite or Group using the Rebuild Sprite/Group command from the editor or rebuilding all materials at once using the Rebuild All Materials command from the editor.

Note: The material displayed on the sprite in the scene view will always be from the first Material Set. When you press play, the sprite will be drawn with the custom material.

Changing Material Sets
The current material set can be changed using the inspector on the Sprite. It can also be changed during gameplay via scripting using Sprite.ChangeMaterialSet.

Material Override vs Material Sets
There are two ways to change materials on sprites:

  1. Assign a material override to the sprite.
  2. Change the current material set on the sprite.

Using a material override simply replaces the current materials on the sprites with instanced materials based on the material chosen. While this works, it has the disadvantage of requiring materials to be instanced for every instance of the sprite on screen. This makes it impossible for these instances of the same sprite to be batched, thus increasing draw calls. Material override is convenient, however, because it does not require any pre-planning or defining of material sets in sprites beforehand.

By contrast, material sets allow every instance of the same sprite to share materials because these materials have been pre-generated and exist on disk. When you have several instances of the same sprite on the screen, the ones that are currently using the same material sets can be batched saving draw calls. This draw call savings can be even more pronounced when drawing sprites that are in a Sprite Group because all sprites in the group that share the same atlas and are using the same material set can potentially be batched. Material Sets must be defined in each Master Sprite or Sprite Group in the editor before use.