Search code examples
unity-game-enginesprite

how i can get and render sprite form dataPath?


Sprite SpriteModding(string path)

{
    byte[] bytes = File.ReadAllBytes(Application.dataPath + "/Resources/fgsoftwarestudio.png");
            Texture2D texture = new Texture2D(512, 512, TextureFormat.RGB24, false);
            texture.filterMode = FilterMode.Trilinear;
            texture.LoadImage(bytes);
            Sprite sprite = Sprite.Create(texture, new Rect(0, 0, 512, 512), new Vector2(0.5f, 0.0f), 1.0f);

            sprite_bg.GetComponent<SpriteRenderer>().sprite = sprite;
            
            return null;

}

` ]1]1

on data path

on game

i open game and sprite don't render


Solution

  • If you are loading a file from resources folder try Resources.Load more information here: Information about Resources folder