Remove sprite reference before build in Unity

All the the characters in my 2D game have SpriteRenderers to animate the characters. Some of the characters are only active in their scenes sometimes, so I load their sprites asynchronously based on game state.

During edit mode, I have at least one sprite from an animation assigned to each sprite renderer so I can tell where the game object is. The problem is that including even a single sprite will load up the entire sprite atlas at runtime if I allow the SpriteRenderer.sprite to be set.

Is there an efficient way to unset the SpriteRenderer.sprite for a build, but not during edit time? Is there a better way to handle this?

EDIT: So I finally had a chance to play around with gizmos and the trouble is that some of my characters require multiple sprite renderers, and the scale of the object doesn't seem to affect the gizmo which is important for positioning within the level.

It would be ideal to have the sprites unset just before building.

Rather than assigning a sprite in the Inspector for visualization purposes, it may be better to visualize these otherwise-invisible GameObjects using gizmos. The most relevant gizmo is probably Gizmos.DrawIcon():

void OnDrawGizmos()
{
Gizmos.DrawIcon(transform.position, "PlaceholderIcon.png", true);
}


The icon image needs to be located in an Assets/Gizmos/ folder.

• That should work great, thank you! May 24, 2021 at 17:37
• @Programmer9000 I see that you un-accepted this answer. Is there a problem with the answer? Do you need additional help? Aug 4, 2021 at 22:23
• Ahh so the trouble is that some of my characters require multiple sprite renderers, and the scale of the object doesn't seem to affect the gizmo which is important for positioning within the level. Aug 13, 2021 at 1:38