How to programmatically assign a frame of a sprite

EDIT:
Foolish me! the code works perfectly, but my sprite was names “letter**s**” not “letter” :wink:

How do I programmatically assign a spritesheet (Sprite /w Sprite Mode = Multiple) to a SpriteRenderer.sprite?

What I’ve tried:

    private Sprite[] spriteSheet;
    private SpriteRenderer spriteRenderer;
    public char character;

    void Start()
    {

        spriteSheet = Resources.LoadAll<Sprite>(PATH_TO_SPRITE + "letters"));
        spriteRenderer = GetComponent<SpriteRenderer>();

        if (Char.ToUpper(character) == 'F')
            spriteRenderer.sprite = spriteSheet[0];
        else if (Char.ToUpper(character) == 'U')
            spriteRenderer.sprite = spriteSheet[1];
        else if (Char.ToUpper(character) == 'N')
            spriteRenderer.sprite = spriteSheet[2];
    }

So just clarity, what you have there is not a spritesheet, but an array of Sprite Classes. A spritesheet is usually defined as one texture with multiple images on it, that you slice up for reference to later. You’d index into this texture at certain x,y locations with width/height to get specific sprites. Often you make spritesheets that are all exactly the same width/height of sprites for animations.

Now your code here:

private Sprite[] spriteSheet;
spriteSheet = Resources.LoadAll<Sprite>(PATH_TO_SPRITE + "letters"));

Is loading up an array of Sprites each with its own texture and all the other things a Sprite has.
That code looks like it should work, what seems to be the problem are no sprites showing up at all?

You can try changing the code to this to nail down where the problem is:

  private Sprite[] spriteSheet;
    private SpriteRenderer spriteRenderer;
    public char character;
    void Start()
    {
        spriteSheet = Resources.LoadAll<Sprite>(PATH_TO_SPRITE + "letters"));
        Debug.Log("I loaded up: " + spriteSheet.Length + " sprites");
        spriteRenderer = GetComponent<SpriteRenderer>();
        if (Char.ToUpper(character) == 'F')
            spriteRenderer.sprite = spriteSheet[0];
        else if (Char.ToUpper(character) == 'U')
            spriteRenderer.sprite = spriteSheet[1];
        else if (Char.ToUpper(character) == 'N')
            spriteRenderer.sprite = spriteSheet[2];
        else
             Debug.Log("You didn't press a valid key");
    }

If you loading up up the correct number of sprites and your key checking code is working. Try loading up just 1 of the sprites in the letters directory and displaying it in a new Empty project. Maybe the sprite itself is messed up in some manner.

I think I was using layman nomenclature, I did indeed split a single image into multiple seperate images, rather than say using x,y coordinates to display a section of a single image.

Thank you for the clarification.

Ah I missed your edit at the top… I see you did have it already working.