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. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Official Tell us about your experience with Sprite Shape

Discussion in '2D' started by rustum, May 29, 2019.

Thread Status:
Not open for further replies.
  1. PrecisionCats

    PrecisionCats

    Joined:
    Nov 19, 2017
    Posts:
    40
    Pixel per unit seems to be cast from float to int. That's definitely a bug
     
  2. BBO_Lagoon

    BBO_Lagoon

    Joined:
    Mar 2, 2017
    Posts:
    186
    Hi, I'm using SpriteShape to create a path with different check point on a map, but when I start my scene with the camera at the end of the map, the SpriteShape is not visible until I scroll down to the start. I there a way to force the SpriteShape to render ?

     
    RedHillbilly likes this.
  3. fergamboa_

    fergamboa_

    Joined:
    Feb 25, 2019
    Posts:
    2
    Hello, I’m having issues in my mobile game related to performance spikes due memory allocation. I’m using 2D SpriteShape - Version 4.1.2 - June 15, 2020 with the Unity Version 2020.2.0a13.1691. That version of Sprite Shape fixes other bugs, and it only works on that Unity Version; hence, I can't go back to a previous version of Unity.

    The memory spikes come from SpriteShapeController.OnWillRenderObject() and go from 13 KB up to 23 KB. Also, here is an image to show the issue in the profiler.


    SpriteShapePlusArrows.jpg
     
  4. mkalipinde

    mkalipinde

    Joined:
    Aug 18, 2017
    Posts:
    2
    Shape not rendering in editor, am on 2019.4
     

    Attached Files:

  5. Enrique48k

    Enrique48k

    Joined:
    Apr 30, 2019
    Posts:
    7
    I have the same problem as "fergamboa_" with SpriteShapeController.OnWillRenderObject (), it generates a lot of garbage.
    Version 2019.4.1f1 with SpriteShape 3.0.12
     
  6. Enrique48k

    Enrique48k

    Joined:
    Apr 30, 2019
    Posts:
    7
    I have solved it !!
    If we disable the "Update Collider" it no longer generates garbage.


    Code (CSharp):
    1.  
    2. using UnityEngine.U2D;
    3.  
    4. var sscAll = SpriteShapeController.FindObjectsOfType<SpriteShapeController>();
    5. foreach(SpriteShapeController ssc in sscAll) {
    6.         ssc.autoUpdateCollider = false;
    7. }
     
    JBR-games likes this.
  7. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    615
    Please take a look at GenerateSpriteShapes.cs which is part of Extras. You can install Extras and Samples in the SpriteShape page in packagemanager. The script will force generation of all Spriteshapes (whether visible or not) on scene start. Just add this script to one of the root gameObject like Camera. Thanks.
     
    b21090, Nightmare34 and RedHillbilly like this.
  8. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    615
    OnWillRenderObject basically tests for any change in the SpriteShape inputs and regenerates geometry if required. If the SpriteShape object is not modified during Runtime, OnWillRenderObject can early exit.

    In 3.0.12 SpriteShape geometry can be baked so its not required to be generated on runtime. For such objects where data is already baked, we are improving OnWillRenderObject so its no longer required each frame. Will post an update once that version is available.
     
  9. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    615
  10. tzarl

    tzarl

    Joined:
    Dec 10, 2019
    Posts:
    1
    I'm trying to modify the transparency of a bunch of spriteshapes at once, but I can't get
    "GetComponentsInChildren<SpriteShapeRenderer>()" to actually find the SpriteShapeRenderer. It always returns an empty array. Here's my code:

    Code (CSharp):
    1.     [SerializeField] public GameObject physical_world;
    2.     SpriteShapeRenderer[] physicalPlatforms;
    3.  
    4.     void Start()
    5.     {
    6.         physicalPlatforms = physical_world.GetComponentsInChildren<SpriteShapeRenderer>();
    7.     }
    in this case "physical_world" is a game object I assigned in the inspector that has all the game objects I want to modify inside it (the spriteshape platforms I want to modify) each with a SpriteShapeController and SpriteShapeRenderer.

    EDIT: Should specify, my version is 2019.3.5f1
     
  11. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    829
    I'm enjoying sprite shape so far, I finally had an excuse to use it.

    One thing that stands out, which Brackeys also pointed out in his video; making assets for sides and bottom is a bit nonsensical for the art pipeline in a game. For example receiving an asset like this:

    Screen Shot 2020-07-14 at 17.11.10.png

    Needs to be edited by the developer to look like this to work in the sprite shape editor:

    Screen Shot 2020-07-14 at 17.11.16.png

    With no rotate function in the sprite editor, this means they need to open an art package to manually change the art asset. Maybe there could be a checkbox that enables 9-slice style graphic layouts so the developer doesn't need to edit the art assets?
     
    Last edited: Jul 14, 2020
  12. BBO_Lagoon

    BBO_Lagoon

    Joined:
    Mar 2, 2017
    Posts:
    186
    @Venkify thanks it works. Would be good to have an easier way of doing it ;)
     
  13. ETGgames

    ETGgames

    Joined:
    Jul 10, 2015
    Posts:
    73
    @Venkify I have submitted a bug report. Sorry I held off for so long, I thought I wouldn't be able to repro, but I've been driven to the edge. The bug report number is 1264015

    UPDATE: I think I fixed it, just had to call BakeMesh() on the sprite shape controller before trying to bake the collider....
     
    Last edited: Jul 17, 2020
  14. IceTrooper

    IceTrooper

    Joined:
    Jul 19, 2015
    Posts:
    35
    I also think that this behavior is quite illogical. Opting for a change.
     
    enhawk likes this.
  15. ETGgames

    ETGgames

    Joined:
    Jul 10, 2015
    Posts:
    73
    It would be nice to have the GeometryCollider in the extras work on a separate thread or something to improve performance. It currently is very slow to load say 50 sprite shapes that bake the geometry collider in awake.
     
  16. Jamez0r

    Jamez0r

    Joined:
    Jul 29, 2019
    Posts:
    199
    Has anyone been able to use a Sprite Shape to SET the mask/stenciling? I'm basically looking to set up the exact same functionality as SpriteMask but for a Sprite Shape.

    My game is top-down and I'd like to use Sprite Shape for a body of water (lake, or river, etc), and also use it as a stencil for reflections/distortion effect on top of the water.

    @Venkify in this post https://forum.unity.com/threads/spriteshape-preview-package.522575/page-2#post-3559862 you mentioned "To achieve this affect your could create a runtime textureless sprite from the Fill area and use it."

    Would anyone be able to elaborate on that a bit? How can I get that Fill area? Is the idea to make that runtime textureless (?) sprite, and set it as the target for a SpriteMask with the desired mask settings?

    (Quick edit question) Are you calling it a "textureless" sprite because it is just using the mesh-shape for the fill area, and wouldn't need any pixel color-data?
     
    Last edited: Jul 19, 2020
  17. PrecisionCats

    PrecisionCats

    Joined:
    Nov 19, 2017
    Posts:
    40
    I think you would need 2 identical sprite shapes, give one a material that increments the stencil, with sorting layer and order in layer for the beginning of the sorting range you want, and the other one a material that decrements the stencil, at the end of the sorting range you want.
    You can make a script that copies the spline information from one to the other, such as this: https://github.com/Unity-Technologies/2d-spriteshape-samples/blob/master/Assets/Unity Technologies/2D SpriteShape/Extras/Scripts/ConformingSpline.cs
     
  18. NotEvenTrying

    NotEvenTrying

    Joined:
    May 17, 2017
    Posts:
    43
    Hi, is it just me or is the issue (raised numerous times since 2019) of spriteshapes using the sprite-lit material not being tinted by the sprite shape renderer's color STILL not fixed? Is this fixed in a specific unity version? I am currently on 2019.3.3f1, with the latest version of the package (3.0.12) available on this editor version. I find it hard to believe that a simple issue affecting a basic, fundamental feature is still not fixed despite a dev responding to this issue being pointed out several months ago saying they already knew what caused it.
     
  19. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    615
    We understand. However adding such a constraint will limit how sprites can be added to Angle-Ranges and removes the flexibility of the existing approach. However we will try to add an asset postprocessor script example that assists in converting an input texture suitable for SpriteShape. Thanks.
     
    RemDust and IceTrooper like this.
  20. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    615
    Collider data itself is generated in a burstable C# Job. However at present Collider2D API only allows updating data in the Main-Thread. Besides GeometryCollider uses the RenderGeometry as Input data to Collider which can be quite heavy for Physics2D. Use GeometryCollider only for objects that require accurate Collision.
     
  21. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    615
    As of now, only sprites are allowed to be used as Mask for SpriteMask. What you could do is get the RenderGeometry of SpriteShape, use this data (vertices and triangles) and create a sprite with this input. You can then use this Sprite for SpriteMask.
     
  22. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    615
    Please update URP to version (7.4.0 / 8.1.0) that has the fix. Thanks.
     
    NotEvenTrying likes this.
  23. pastaluego

    pastaluego

    Joined:
    Mar 30, 2017
    Posts:
    192
    @Venkify
    I just updated to 2020.1. Were the EditorPrefs snap variable names changed? Spriteshape doesn't seem to be responding to changes to the Snap values in Edit>Grid And Snap Settings and is instead stuck at snapping to 0.25, which is what I had set to I assume is now the old EditorPrefs.GetFloat("MoveSnapX"); value, whose value isn't changing anymore when I change the snap value via editor in the Grid and Snap Settings, and it always did in 2019.3 and earlier.

    *After looking more, I'm guessing that EditorPrefs.MoveSnapX/Y/Z values are obsolete for the snap settings and it uses UnityEditor.EditorSnapSettings.move value now?"
     
    Last edited: Jul 27, 2020
  24. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,269
    SpriteShape should check if the shape has actually changed before updating collider.
    This currently is creating performance issues at runtime, constantly (and unnecessarily) rebuilding collider.
    If the shape itself is a prefab, the prefab always becomes dirty upon selecting it. Very annoying.
    Comparing the "BakeMesh" with "BakeCollider":
    spriteshape_bakemesh.png
    spriteshape_bakecollider.png
    This is bad. If autoUpdateCollider is true, you're looking at GC every frame making all these lists and arrays. And in edit mode, you're constantly making the edge/polygon collider dirty, no matter if something changed or not.

    Why can't "BakeCollider" use similar logic to "BakeMesh" where before updating the collider, it checks if anything has changed. This would solve a lot of perf problems and editor issues I'm currently facing.

    There is also a lot going on here just to check if things have changed too. If I have a lots of sprite shapes primarily used for terrain that I know will never change, I shouldn't need to pay the penalty of all these checks at runtime. I'd like an option on the sprite shape to "only update in edit mode". So essentially "OnWillRenderObject" does nothing at runtime.

    Something like this:

    Code (CSharp):
    1.  
    2. #if UNITY_EDITOR
    3. using UnityEditor;
    4. #endif
    5.  
    6. namespace UnityEngine.U2D {
    7.  
    8.     public class CachedSpriteShapeController : SpriteShapeController {
    9.  
    10.         [System.NonSerialized] private bool hasCached = false;
    11.  
    12.         [SerializeField] private int cachedSplineHash = 0;
    13.         [SerializeField] private int cachedShapeHash = 0;
    14.         [SerializeField] private int cachedParameters = 0;
    15.  
    16.         #region Unity Methods
    17.  
    18.         void OnWillRenderObject() {
    19.  
    20. #if UNITY_EDITOR
    21.             if (!EditorApplication.isPlaying) {
    22.  
    23.                 UpdateColliderInEditor();
    24.                 BakeMesh();
    25.                 return;
    26.             }
    27. #endif
    28.             if (!hasCached) {
    29.  
    30.                 BakeCollider();
    31.                 BakeMesh();
    32.  
    33.                 hasCached = true;
    34.             }
    35.         }
    36.  
    37.         #endregion
    38.  
    39.         #region Private Methods
    40.  
    41. #if UNITY_EDITOR
    42.         private void UpdateColliderInEditor() {
    43.  
    44.             int parametersHash = spriteShapeParameters.GetHashCode();
    45.  
    46.             bool splineChanged = splineHashCode != 0 && cachedSplineHash != splineHashCode;
    47.             bool spriteShapeChanged = spriteShapeHashCode != 0 && cachedShapeHash != spriteShapeHashCode;
    48.             bool parametersChanged = parametersHash != 0 && cachedParameters != parametersHash;
    49.  
    50.             if (splineChanged || spriteShapeChanged || parametersChanged) {
    51.  
    52.                 Undo.RecordObject(this, "Update Collider");
    53.  
    54.                 cachedSplineHash = splineHashCode;
    55.                 cachedShapeHash = spriteShapeHashCode;
    56.                 cachedParameters = parametersHash;
    57.  
    58.                 BakeCollider();
    59.             }
    60.         }
    61. #endif
    62.         #endregion
    63.     }
    64. }
    65.  
     
    Last edited: Jul 27, 2020
  25. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,269
    Please consider something like a cached sprite shape controller.
    Here's some profiling between the two.

    normal SpriteShapeController (1.5kb GC every frame) with nothing changing:
    spriteshape profiler.png

    Vs cached sprite shape (0 GC every frame)
    cachedspriteshape profiler.png
     
  26. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    615
  27. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    615
    Yes, this has already been fixed in 3.0.13, 4.1.13, 5.0.1 which hopefully will be available this week. Thanks for reporting.
     
    CDF likes this.
  28. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,269
    Nice, looking forward to checking out
     
  29. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    829
    Sounds nice as an option, would help a lot.

    Would be good to make sprite shape from graphics like this
    block1.png

    Instead of this:
    block2.png

    Also worth noting, the graphics may come on a sheet with other graphics not as a single block on it's own.
     
    Last edited: Jul 29, 2020
    RemDust likes this.
  30. Rob4

    Rob4

    Joined:
    Aug 4, 2017
    Posts:
    8
    Hello,
    I was wondering if someone here can help me.
    I am procedurally generating some vector2 at runtime and then feeding it into a sprite shape spline. I generally like the result, but unfortunately if i set the tangent mode to continuous during the loop, it doesn't automatically generate the control points for the position, like it does when you manually set up the points in the inspector. Is there any way to call this functionallity from a script? Or can someone tell me why exactly it is not happening?
    I tried always setting the tangent mode for the previous point, since i imagined that it maybe needs the following point, but that didn't help. I also tried setting the tangents myself, with "spline.SetRightTangent" and the left counterpart of it, but that gave me strange results.
     
    Last edited: Jul 29, 2020
  31. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    829
    we are having this same problem, where is "extras"?

    Screen Shot 2020-07-31 at 18.18.01.png
     
  32. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    615
    Extras and Samples are available in recent versions (3.x.x and above) of SpriteShape within PackageManager

    image.png
     
  33. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    829
    Any plans to make available in 2018 LTS? On need to be on 2019+?
     
  34. PrecisionCats

    PrecisionCats

    Joined:
    Nov 19, 2017
    Posts:
    40
    This is a strange bug:
    Strange.PNG
    Strange 2.PNG
     
  35. kactus223

    kactus223

    Joined:
    May 20, 2014
    Posts:
    35
    Hi. I'm trying to investigate some performance issues in our project and found that the part of code that checks for changes in spline & sprite shape is quite heavy too. For the BakeCollider method, I can just disable autoUpdateCollider, but is there a way to optimize this BakeMesh method, like can we just set the mesh data to the renderer once and not updating it again (because our sprite mesh is static)?
     

    Attached Files:

  36. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    615
    @kactus223 Please take a look at Bake Geometry feature :

    https://forum.unity.com/threads/how-to-bake-sprite-shape.956529/#post-6261118

    This is available since 5.0.1 (2020.2), 4.1.1 (2020.1) and 3.0.12 (2019.*) versions of the SpriteShape package.
     
  37. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    615
  38. n8dev_yt

    n8dev_yt

    Joined:
    Apr 14, 2020
    Posts:
    22
    This is a really nice tool, I love it, but when doing raycasting, the edge collider is missed, and it instead pretends that my edge collider has no offset and just hits that
    EDIT: this is probably a bug, but when I just adjusted the offset to 0, then back to what I originally had in the prefabs, it works fine.... weird
     
    Last edited: Sep 5, 2020
  39. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    829
    @Venkify there seems to be a bug in 3.0.12 on Unity 2019.4.9f1 where the corners don't draw properly, specifically top right and bottom right.
     

    Attached Files:

    Last edited: Sep 19, 2020
  40. PhantomFox128

    PhantomFox128

    Joined:
    May 22, 2019
    Posts:
    157
    I know this has probably been asked a dozen times, but how do you get the corners to show? I've set up everything properly as far as I know, but it still doesn't work and I can't find anything on this that's up to date.
     
  41. n8dev_yt

    n8dev_yt

    Joined:
    Apr 14, 2020
    Posts:
    22
    make sure that your points are curves, and not segments
     
  42. BACALL

    BACALL

    Joined:
    Feb 21, 2017
    Posts:
    79
    Is there a way to invert the fill (for creating rooms, or caves and other interiors), or am I missing something?
     
  43. NRB007

    NRB007

    Joined:
    Jan 31, 2016
    Posts:
    3
    How to get spline path in sprite shape controller spline class
    As we are getting only point position not any point in spline with input 0 to 1.
     
  44. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    615
    Could you please submit a bug report for this ? Thanks.
     
  45. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    615
    Could you please post a screenshot or more info on that ? Thanks.
     
  46. enhawk

    enhawk

    Joined:
    Aug 22, 2013
    Posts:
    829
    it seems to be fixed in 2019.4.10
     
  47. BlackSpoonGames

    BlackSpoonGames

    Joined:
    Oct 2, 2016
    Posts:
    1
    Is there some way to use sprite shape with Animation component without HUGE of GC allocations (100kb per frame for 10pnt shape)? I turned off the Adaptive UV, turned off the Auto-update collider, turned on the geometry cache, but all the same, when playing the animation (just spinning the transform) on SpriteShape, almost empty scene with a 10-point shape gives a very strong fps drop on a high-end Android device.

    Unity 2020.1.8f1

    upload_2020-10-20_14-51-55.png
     
    Last edited: Oct 20, 2020
  48. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    615
    @BlackSpoonGames

    If you are animating/modifying SpriteShape on Runtime, please make sure to install Burst package to improve performance.
    Note: Open Shapes are fully tessellated in a Burst compatible C# Job, involves very little GC and performant. Closed Shapes might incur some GC allocations for Fill Tessellation. But we are optimising this in an upcoming version. Will post an update here once its published.

    If you are not modifying SpriteShape on the Runtime, please turn on "Cache Geometry". This should prevent GC allocations as no Tessellation is performed and stored geometry data is used instead.

    Could you please let us know the version of Unity/Spriteshape you are using ? If the issue persist, kindly submit a bug report and we will take a look asap..
     
  49. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,269
    Where exactly is the "cache geometry" setting? I don't see it in the inspector and no information about it on the documentation.
     
  50. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    615
    "Cache Geometry" option is available when you Enter Edit mode.



    Please note : There may still be GC in Editor/Playmode but very little GC in the Player when "Cache Geometry" is enabled.
     
    CDF likes this.
Thread Status:
Not open for further replies.