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

Question Get/Set Sprite Custom Outline from script?

Discussion in '2D' started by Lo-renzo, Sep 23, 2020.

  1. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,319
    I'd like to get/set custom outlines (like in Sprite Editor) from a script in Editor.

    From the meta file:
    Capture - Copy.PNG

    I can modify other properties of spritesheet with the TextureImporter Settings/Properties, but I'm struggling to find the spot for adjusting the outline. If there's no public way to do this, is modifying the .meta file directly dangerous?
     
  2. DiegoDePalacio

    DiegoDePalacio

    Unity Technologies

    Joined:
    Oct 28, 2009
    Posts:
    506
    Hi @Lo-renzo,

    Modifying the outline is not exposed to the public API for you to change it directly, as you can see here: https://docs.unity3d.com/ScriptReference/SpriteMetaData.html

    However, as you mentioned, it's possible to change it directly by modifying the meta file.

    You can find a working example of how you can do it here: https://forum.unity.com/threads/setting-custom-sprite-outline-via-script-asset-postprocessor.697298/

    Using this specific method in the Editor is not dangerous if you use the proper values ;)


    Good luck with it!
     
    Lo-renzo likes this.
  3. Joseguepardo

    Joseguepardo

    Joined:
    Mar 3, 2015
    Posts:
    8
    Hey @DiegoDePalacio, and why is this not exposed in the public API? Seems like an unnecessarily complex workaround for something that shouldn't be difficult to achieve :(
     
  4. MarekUnity

    MarekUnity

    Unity Technologies

    Joined:
    Jan 6, 2017
    Posts:
    179
  5. theforgot3n1

    theforgot3n1

    Joined:
    Sep 26, 2018
    Posts:
    188
    Do we know of any other outline implementations done except for the Unity one?
    For example, in my case I'm using 1024x1024 textures which I'd like to use an outline for. The built-in Unity outline creates too many verts (189 tris, 184 verts), which in my case would suffice with just 10 or 15 verts to remove most of the transparent area.
    Would be great if there were some implementations lying around!