Skip to content

SpriteRendererComponent

The visible image on a 2D entity.

csharp
public class Enemy : GameEntity
{
    private SpriteRendererComponent? m_Sprite;

    protected override void OnCreate()
    {
        m_Sprite = GetComponent<SpriteRendererComponent>();
    }

    public void Flash()
    {
        m_Sprite!.Color = new Vector4(1, 0.3f, 0.3f, 1);
    }
}

Color

A tint multiplied into the sprite's texture, as a Vector4 of red, green, blue and alpha, each 0 to 1. Read and write.

csharp
m_Sprite.Color = new Vector4(1, 1, 1, 1);        // untouched
m_Sprite.Color = new Vector4(1, 0.3f, 0.3f, 1);  // red hit flash
m_Sprite.Color = new Vector4(1, 1, 1, 0.5f);     // half transparent

There is no Color type

Colours are Vector4 throughout the API — here, on TextComponent, on UIImage and in Material.SetColor. Give yourself named constants if you use the same few often:

csharp
private static readonly Vector4 White = new Vector4(1, 1, 1, 1);
private static readonly Vector4 HitRed = new Vector4(1, 0.3f, 0.3f, 1);

Fading a sprite out is the common use, and it's a coroutine:

csharp
private System.Collections.IEnumerator FadeOut(float duration)
{
    float t = 0;
    while (t < duration)
    {
        t += Time.DeltaTime;
        m_Sprite!.Color = new Vector4(1, 1, 1, 1 - t / duration);
        yield return null;
    }
}

TexturePath

The sprite's texture, as a path relative to your Assets folder. Read and write. Takes effect on the next frame's draw.

csharp
m_Sprite.TexturePath = "Textures/PlayerHurt.png";

Any format the engine imports works here — .png, .jpg, .bmp, .tga, .hdr, and .svg (a vector icon assigned here rasterises through the same path a .png would).

Swapping textures is not an animation system

This is for state changes — a damaged variant, a different character skin, a themed icon. For frame-by-frame animation use a sprite sheet and an Animator, which batches properly and doesn't re-resolve an asset path on every change.

What isn't scriptable

Sorting layer, order in layer and the material slot are set in the Properties panel; there's no C# access to them in 0.1.0. For per-entity material parameters, load and instantiate a material directly instead — see Material.

See also

  • Material — custom shaders and per-entity parameter overrides
  • Animator — driving sprites from animation clips
  • Rendering — sorting layers, atlases, and batching