Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Edit builtin sprites

Discussion in 'UGUI & TextMesh Pro' started by mathiasj, Jun 7, 2016.

  1. mathiasj

    mathiasj

    Joined:
    Nov 3, 2015
    Posts:
    64
    Hello,
    is there any way to access the built-in UI sprites such as DropdownArrow, Checkmark or UISprite? I just need the location of them on my hard drive but the only thing I could find was a file named unity_builtin_extra that I couldn't open.
    I want to edit these sprites with an image editor but I can't find them.

    Thanks!
     
  2. crispybeans

    crispybeans

    Joined:
    Apr 13, 2015
    Posts:
    210
    You should be able to create a render texture with a transparent background and render the built in sprite to it and then save it to a png again. I did that for all the builtin textures, you still need to same the UISkin and use a custom version if you want that. That can be done by programaticly copying property values into a new UISkin instance wiith some editor script code.
     
  3. mathiasj

    mathiasj

    Joined:
    Nov 3, 2015
    Posts:
    64
    How do I do that? I thought RenderTextures were only used to render from the camera? How would I render the sprite to it?

    Everything I could come up with was this:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.IO;
    4. using UnityEngine.UI;
    5. using UnityEditor;
    6.  
    7. public class CreateSpriteFile : MonoBehaviour {
    8.  
    9.     private const string path = "UI/Skin/Checkmark.psd";
    10.  
    11.     [MenuItem("Tools/Save sprites to hard drive")]
    12.     private static void NewMenuOption()
    13.     {
    14.         Image image = GameObject.Find("Main").AddComponent<Image>();
    15.         image.sprite = AssetDatabase.GetBuiltinExtraResource<Sprite>(path);
    16.         Texture2D texture = image.sprite.texture;
    17.         byte[] bytes = texture.EncodeToPNG();
    18.         File.WriteAllBytes("C:/Users/Mathias/Desktop/Sprites/checkmark.png", bytes);
    19.     }
    20. }
    21.  
    But it does not work; I get the following exception:

    UnityException: Texture 'Checkmark' is not readable, the texture memory can not be accessed from scripts. You can make the texture readable in the Texture Import Settings.
    CreateSpriteFile.NewMenuOption () (at Assets/Editor/CreateSpriteFile.cs:17)
     
  4. mathiasj

    mathiasj

    Joined:
    Nov 3, 2015
    Posts:
    64
    Does no one have a solution for this?
     
  5. joosthoi1

    joosthoi1

    Joined:
    Jun 17, 2020
    Posts:
    1
    You can drag the sprite from the inspector into a public sprite variable