Is it possible to get a sprite via string?

I know my question sounds dumb, but I am trying to make a simple game where the player can customize the game by putting their assets into a folder called “assets” in the “[Game]_Data” folder.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GetData : MonoBehaviour
{

    public GameObject background;

    // Start is called before the first frame update
    void Start()
    {
        background.GetComponent<SpriteRenderer>().sprite = // Here is where I'm stuck.

        /*
        Attempted Solutions:

            = Application.dataPath + "ModAssets/background/bg.png";
            = Resources.Load("bg.png");
        */
    }
}

What I’m trying to get it to do is find the “bg.png” file and use it to set the background.
If there is, is there a way to do this with sounds too?
Is it possible to do this? Or is that not possible?

Unity Version: 2019.4.28f1

Get bytes from file: File.ReadAllBytes(String) Method (System.IO) | Microsoft Learn
Read raw image bytes into Texture2D: Unity - Scripting API: ImageConversion.LoadImage
Create Sprite from Texture2D: Unity - Scripting API: Sprite.Create

1 Like

THANK YOU SO MUCH! It worked!