assets
Determining Sprite Source Atlas vs Asset
Solution
Unity 2021.3.x - Unity 6.3.x
Published Thu, Mar 19
Identifying whether a Sprite is sourced from a SpriteAtlas or a direct asset is essential for verifying memory usage and ensuring efficient batching during the rendering process.
Access the sprite.texture.name property or utilize the Frame Debugger to identify the active SpriteAtlas and verify memory source.
The origin of a loaded Sprite is verified through editor tools or programmatic inspection. Using the Frame Debugger provides visibility into the textures being processed during the render loop.
- Open the
Frame Debuggervia Window > Analysis. - Analyze the draw call to see if the texture belongs to a SpriteAtlas.
- Use your script to access the
sprite.texture.nameproperty at runtime. - Observe the returned string; it matches the SpriteAtlas name when packed.
Additional Tips
- Use the
Sprite.packedproperty to verify packing status without string comparison. - Check your sprite settings to ensure the Packing Mode is set correctly in the
Inspector. - Sprites packed into a SpriteAtlas share the same
Texture2Dreference, which reduces draw calls.
using UnityEngine;
public class SpriteSourceIdentifier : MonoBehaviour
{
[SerializeField] private SpriteRenderer spriteRenderer;
private void Start()
{
if (spriteRenderer == null) spriteRenderer = GetComponent<SpriteRenderer>();
if (spriteRenderer != null && spriteRenderer.sprite != null)
{
// The texture name identifies the source
string sourceName = spriteRenderer.sprite.texture.name;
bool isPacked = spriteRenderer.sprite.packed;
Debug.Log($"Sprite: {spriteRenderer.sprite.name} | Source: {sourceName} | Packed: {isPacked}");
}
}
}
Related Posts Haven't quite found a solution to your problem? We think these posts might help you.
[Vector Graphics] Referencing SVG Assets via C# Scripts[Physics2D] 2D Raycast Component Filtering Issues[VideoPlayer] Rendering Halts After Reactivation
Content inspired by a Unity discussion post.