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. Join us on Thursday, June 8, for a Q&A with Unity's Content Pipeline group here on the forum, and on the Unity Discord, and discuss topics around Content Build, Import Workflows, Asset Database, and Addressables!
    Dismiss Notice

Official 2D Sprite Shape 6.0 released for Unity 2021.1

Discussion in '2D' started by rustum, May 10, 2021.

  1. mokalux

    mokalux

    Joined:
    Feb 26, 2022
    Posts:
    1
    snapping option (in sprite shape contoller) gets deactivated when I go from one sprite shape to another, is it a bug?
     
    Last edited: Apr 5, 2022
  2. useraccount1

    useraccount1

    Joined:
    Mar 31, 2018
    Posts:
    241
    upload_2022-4-9_13-36-50.png

    When I press the button to modify points of sprite shape, it gets darker.
    But When I press the button to modify points of the collider, it gets brighter.

    It took me a moment to figure this out. Would be a nice thing to improve (by changing the coloration of the edit collider button).

    Also, the reason why I would want to edit the collider:

    upload_2022-4-9_13-20-25.png

    The bottom shows the result of the automatic generation. There is this one line that goes through the middle of the shape. To fix this issue, I make the shape on the top.
     
  3. useraccount1

    useraccount1

    Joined:
    Mar 31, 2018
    Posts:
    241
    One more issue I have with sprite shapes - the shadow caster component requires manually setting points.
     
  4. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,104
    There's a bug with SpriteShapes when we upgrade from 2020 to 2021.

    Here's two screenshots
    1 is from from Unity 2020.3.33f1, URP 10.8.1, and SpriteShape 5.3.0.

    upload_2022-4-25_11-55-39.png

    2 is from Unity 2021.3.1f1, URP 12.1.6, and SpriteShape 7.0.4:
    upload_2022-4-25_11-56-31.png

    As you can tell, both has a SpriteShape using Sprite-Lit-Default for it's materials, and with the color set to have a low alpha value. In the 2020 screenshot, the SpriteShape is transparent, as it should be, but in the 2021 screenshot, the SpriteShape is opaque. Changing the alpha value of the color field does nothing in the 2021 version.

    This seems to relate to lights; if I turn off lights in the scene view in the second screenshot, the SpriteShape is transparent, as intended.


    This bug - reported as 1422703 - is currently blocking us from updating from 2020 to 2021.
     
  5. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,104
    Found the issue. CombinedShapeLightShared got changed, and introduced the bug. Here's the relevant parts from the URP 10.8.1 version:

    Code (csharp):
    1.  
    2. half4 CombinedShapeLightShared(half4 color, half4 mask, half2 lightingUV)
    3. {
    4.    if (color.a == 0.0)
    5.       discard;
    6.  
    7.     color = color * _RendererColor; // This is needed for sprite shape
    8.  
    9.     ...
    10.  
    11.    
    12.     finalOutput.a = color.a;
    13.  
    14.     finalOutput = finalOutput *_UseSceneLighting + (1 - _UseSceneLighting)*color;
    15.     return max(0, finalOutput);
    16.  
    Here's the relevant parts from URP 12.1.6:

    Code (csharp):
    1.  
    2. half4 CombinedShapeLightShared(in SurfaceData2D surfaceData, in InputData2D inputData)
    3. {
    4.     ...
    5.  
    6.     half alpha = surfaceData.alpha;
    7.     half4 color = half4(surfaceData.albedo, alpha);
    8.  
    9.     ...
    10.  
    11.     color = color * _RendererColor; // This is needed for sprite shape
    12.  
    13.     ...
    14.  
    15.     finalOutput.a = alpha;
    16.     finalOutput = lerp(color, finalOutput, _UseSceneLighting);
    17.  
    18.     return max(0, finalOutput);
    19.  
    If you look closely, you can tell that the alpha value of the variable marked with "This is needed for sprite shape" isn't used.
     
    DragonCoder likes this.
  6. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    605
    Many thanks for reporting the issue. Will fix it at the earliest. Sorry for any inconvenience caused.
     
    Baste likes this.
  7. indie6

    indie6

    Joined:
    Dec 15, 2012
    Posts:
    91
    Hi @Venkify

    I am making a physics based game in which I modify the SpriteShape at runtime.
    The shape uses an EdgeCollider2D. Since, it's a physics based game, I want to update the collider in FixedUpdate, but looking at the SpriteShapeController.cs, the collider is being Baked in LateUpdate

    My question, is it possible to somehow change the Baking in FixedUpdate?

    And can I get access to m_ColliderData so I can use it to create my own collider and reduce garbage collection?I think for this if I can get a utility method to interpolate between two spline points, that will work as well

    Thanks!
     
    Last edited: May 17, 2022
  8. indie6

    indie6

    Joined:
    Dec 15, 2012
    Posts:
    91
    For anyone else looking on creating your own collider, I used BezierUtility's BezierPoint method
    One question regarding that. How can I add offset to the collider? When I add the offset using (point + pointNormal * offset), it ruin's the curvature. Any help with that @Venkify? Thank you so much!
     
    Last edited: May 22, 2022
  9. wedgiebee

    wedgiebee

    Joined:
    Aug 9, 2016
    Posts:
    37

    @hawken That looks awesome! Did you end up making that tutorial?
     
  10. hawken

    hawken

    Joined:
    Aug 22, 2013
    Posts:
    826
    Thanks! I may revisit this at some point, on the shelf for now
     
    wedgiebee likes this.
  11. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    605
    Have you tried using the Offset of Collider through the Inspector ?

    upload_2022-5-24_15-44-51.png
     
  12. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    605
    I believe one such way is posted here :
    https://forum.unity.com/threads/sprite-shape-interiors.1275836/#post-8100278

    Also, SpriteShape version 9.0 onwards the ability to generate custom geometry/shapes by completely replacing or adding on to the default SpriteShape generator script is available. We will be adding more samples for this version soon. Will post an update.
     
    hawken and wedgiebee like this.
  13. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,104
    I'm running into some bad issues with SpriteShape's mesh generation. We have seen the same thing for a long time, but I've got some instances now where it's a dealbreaker.

    Here's what happens if you create a new closed SpriteShape, and then assign the "Basic" profile from the samples to it:

    upload_2022-5-24_14-24-9.png

    As you can tell, there's a ton of bad artifacts all over the place. This is causing visible artifacts in a lot of places in our game, and we often have to work around it by fidgeting a lot with the SpriteShape.

    I have sent a bug report (will post the number when it's through), but I figured I'd share some details in case it helps.
    Here's what happens if I assign a material with backface culling to the SpriteShape and look at it from behind;

    upload_2022-5-24_14-30-50.png

    As you can tell, all the spots that have artifacts have inverted triangles associated with them.


    I've also used SpriteShapeRenderer.GetChannels in order to extract the mesh data, and then exported that using the fbx exporter. Looking at the same mesh in blender, it's somewhat clear what's happening - some of the triangles have ended up overlapping each other badly, and in all of those cases the overlapping space also contains an inverted triangle. So it very much seems like a bug in the geometry generation.

    This bug is also visible in some of the sample scenes, though less directly. If you look at the "1 Basics" scene, these artifacts are visible if you zoom in on the upper right or left of the shape, and in some different spots. A good way to spot all the artifacts there is to exit 2D mode, look at the mesh from behind, and turn the scene view to "Shaded Wireframe". That will make all the very thin inverted triangles very visible.

    Any idea about a way I could go about fixing this on my own? I'm open to editing SpriteShape in order to make it happen, we're already tracking our own fork in order to do some things (I have tested all of the bugs in a vanilla version of SpriteShape, though!)
     
  14. indie6

    indie6

    Joined:
    Dec 15, 2012
    Posts:
    91
    I am using my own logic to create edge collider 2d using BezierUtility's BezierPoint method. It works fine if I don't give it any offset, but when I do the curvature of the collider is not exactly the same as the shape.

    To add offset, I use this.. I hope this is correct?
    Code (CSharp):
    1. point = point + pointNormal * offset
     
    Last edited: May 24, 2022
  15. wedgiebee

    wedgiebee

    Joined:
    Aug 9, 2016
    Posts:
    37
    Got it, so that's only available on Unity 2022.2 beta which is cool.

    I'm not familiar with writing Jobs code, so really looking forward to seeing how an interior space is made in those samples! In the meantime I'll be using the method in the link you posted, thanks for the reply.
     
  16. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    605
    Yes, it seems that the winding order is reversed for a few triangles that overlap. Will take a look as soon as possible. Please do post the bug report ID and kindly ensure you attach a sample project to verify. Thanks again for posting.
     
  17. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,104
    There's apparently a new bug reporting system? I've sent a bug report with a repro.

    The ID I got was IN-3083, and the link in the email takes me to a jira login page rather than the fogbugz bug tracker. New setup?
     
  18. hawken

    hawken

    Joined:
    Aug 22, 2013
    Posts:
    826
    This technique looks great!

    I used custom collider shapes and sprite masks, I think! It was a while ago now.
     
  19. PaulMDev

    PaulMDev

    Joined:
    Feb 19, 2019
    Posts:
    58
    Same issue here !

    I'm using a lot of gradients in my current project to darken parts of the environment and THIS keeps happening.
    It's really annoying, a little random and a nightmare to avoid.
     

    Attached Files:

  20. indie6

    indie6

    Joined:
    Dec 15, 2012
    Posts:
    91
    were you able to find a fix for this? it's quite annoying when you continuously have to toggle on the snap again and again
     
  21. midsummer

    midsummer

    Joined:
    Jan 12, 2017
    Posts:
    32
    Oh, that's just a feature. Or at least it was until Sprite Shape 8.0, which requires editor version 2022.1. My project could not be upgraded entirely without problems, so I have to continue with 2021.3 for now. I must have clicked the snapping checkbox a thousand times by now.

    I did give Sprite Shape 8.0 a quick try today. Grid snapping now works the way one would expect it to work, it's a much more pleasant editing experience. It's just a pity that Unity 2022.1 froze three times for some unknown reason during my 10 minutes of testing...
     
  22. indie6

    indie6

    Joined:
    Dec 15, 2012
    Posts:
    91
    Thanks! I'll try out 2022.1

    For me 2021.3.4f1 starts to slowdown after sometime and I have to restart the editor every time.. 2020.3f12 works fine.. Seems like there are memory leaks in 2021.3 and maybe 2022.1 as well?
     
  23. Antoniusaft

    Antoniusaft

    Joined:
    Feb 28, 2013
    Posts:
    10
    Hi. I use Sprite Shape a LOT in my game, but there is a small feature that I really want to see. I can't figure out if it's possible to do currently.
    I want to be able to flip sprites at individual spline points. (just like the sprite renderer flip options)
    So I don't have to add duplicate flipped textures into my project. Does anyone know if that is somehow possible?
     
  24. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    605
    Sorry for the delay in response. The issue basically happens when the Sprite's size is larger than the actual area it occupies along the spline. This inevitably results in overlaps and there may not be trivial way to fix this for all use-cases. However we are working on minimizing such artefacts. Apologies for the inconvenience caused. Will post an update soon.
     
    Baste and PaulMDev like this.
  25. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,104
    I've got a major bone to pick with SpriteShape and rebaking. The tl;dr is that the baking implementation is causing major workflow issues with scenes constantly having thousands of lines of changes in version control.


    We're caching geometry in order to prevent frame drops and speed up scene loading. This has caused us to run into something very bad; SpriteShape doesn't serialize the things it needs in order to see if the spline has updated.

    So if you open a scene with a SpriteShape with a geometry cache on it, and then hit save, this happens:
    -
    SpriteShapeUpdateCache.SaveSpriteShapesInScene
    is called because you're saving the scene
    - this causes each SpriteShapeController to do BakeMesh().Complete()
    - BakeMesh() checks if the hashes of the spline has changed. But since the hashes (eg.
    m_ActiveSplineHash) isn't serialized, it's 0, so the check always passes the first time this is called (ie. the first time the scene is saved after getting opened).
    - The mesh is baked. For some reason (probably because it is multithreaded), the result isn't completely deterministic - there's minor floating point differences.
    - These differences gets uploaded to the SpriteShapeGeometryCache
    - Our git log now has a couple of hundred of lines of change that look like this, all in SpriteShapeGeometryCache's arrays (m_PosArray etc.)
    upload_2022-8-31_9-50-59.png
    ... as a side-effect of doing nothing else than:
    Code (csharp):
    1. EditorSceneManager.OpenScene("Assets/Samples/2D SpriteShape/7.0.4/Sprite Shape Samples/1 Basics.unity", OpenSceneMode.Single);
    2. var scene = SceneManager.GetActiveScene();
    3. EditorSceneManager.SaveScene(scene);
    We can probably fix this by caching the geometry in PostProcessScene, although that is only possible by modifying the package since all the caching is internal to the package.

    There's two things that ought to be fixed:
    - non-deterministic SpriteShape generation. The code is ECS hell so I haven't bothered trying to touch it.
    - Unity is rebaking every single SpriteShape the first time you hit save after you open a scene, even if there's a cache there. That's doing work that doesn't have to happen!
     
    apparition likes this.
  26. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    605
    Most likely a Burst SIMD optimization resulting in minor floating point differences.
    Yep, will take a look asap. Thanks.
     
  27. demimonde

    demimonde

    Joined:
    May 3, 2021
    Posts:
    26
    Will the 8.0+ versions of Sprite Shape remain exclusive to 2022+? Or is there any chance of them coming to 2021 LTS?
     
  28. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    605
    New features (especially ability to use a custom geometry generator) shipped with 8.0+ wont be backported to versions lower than 2022. Bugfixes will definitely be backported though.
     
    demimonde likes this.
  29. Antoniusaft

    Antoniusaft

    Joined:
    Feb 28, 2013
    Posts:
    10
    Hey there.

    I feel that the new "element inspector" for editing Spline Control Points is slightly problematic, particularly because it is not possible to resize the window, as far as I can tell.

    upload_2022-10-10_13-9-9.png

    As you can see here, under the Sprite Vaiant window, I can either choose between the sprite icons being so small that it is impossible to tell which sprite I am using, or - to zoom in, only to have it be very cumbersome to browse through the sprites.

    I use Sprite Shapes A LOT in our game, and I have profiles with quite a lot of sprite edges. Browsing through them and selecting the correct one is critical for workflow, and this "neat" little inspector is causing more problematic than it is helpful I am afraid.

    Can anyone in here help me figure out if there is a hacky or non-hacky way to resize the window?
    Any help is much appreciated. :)
     
  30. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,104
    You can still do it in the inspector, right? Or is that too small as well?

    The overlay windows are not resizable. The sprite Variant layout is just laid out kinda jankily here - it should be getting the entire width of the inspector, not just half of it.

    Probably the only way to deal with it on your own is to change the package.
     
  31. PhantasmicDev

    PhantasmicDev

    Joined:
    Jul 10, 2013
    Posts:
    32
    Is there a way to have a open ended SpriteShapeController update a PolygonCollider2D to outline the whole sprite shape? I can only get it to outline the side of the sprite shape that is convex but the side that is concave doesn't follow the sprite shape's outline. Is this intentional for open ended sprite shapes? I'd like to make a platform that follows a spline and has collisions on both sides.
     
  32. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,104
    Did you ever have time to look at any of these?

    In addition, the wrong winding thing I posted about last May (IN-3083) got closed with "This issue is already known and being worked on right now. Unfortunately, I cannot provide a link to track the issue due to it being private".

    Do you know what happened with that bug?
     
  33. AnaWilliam850

    AnaWilliam850

    Joined:
    Dec 23, 2022
    Posts:
    36
    thanks for the announcement of the release, it seems really good
     
  34. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    605
    I did take a look at this issue a while back. The issue actually occurs because of the overlaps and not really due to winding order. This is a tricky issue with offset splines that also has to smoothly interpolate uvs as well. While we take a look at improving this, please ensure to avoid overlaps or that the edge sprites are sized appropriately.
     
    Last edited: Jan 20, 2023
  35. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,104
    Thanks!

    There's no documentation that I have found anywhere on how we're supposed to author the sprites for the SpriteShape. So is there any way I can "size appropriately" other than trial and error?

    The docs says things about using Full Rect and packing options and such, but there seems to be nothing about the sprite edge sizes.
     
  36. GebF92

    GebF92

    Joined:
    Oct 16, 2019
    Posts:
    13
    Am I the only one still having this problem?



    Why do corners have problems when the rest of the spline is continuous?
     
  37. wedgiebee

    wedgiebee

    Joined:
    Aug 9, 2016
    Posts:
    37
    Hi @Venkify , just checking, did the samples for making SpriteShape interiors using custom geometry generation ever get posted somewhere?
     
  38. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    605
  39. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    605
    Could you please provide more info or a simple test scene to take a closer look?
     
  40. wedgiebee

    wedgiebee

    Joined:
    Aug 9, 2016
    Posts:
    37
    Hi @Venkify , I believe that's the link you already posted in the post I replied to:
    ---

    I'm talking about this part, where you mentioned examples using the custom geometry generation available in 9.0 onwards. Are there examples for that?
     
  41. indie6

    indie6

    Joined:
    Dec 15, 2012
    Posts:
    91
    @Venkify any update on this? I haven't been able to find an example for the custom geometry generation
     
    wedgiebee likes this.
  42. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    605
    A sample script for custom generation is added under Samples/Scripts/SpriteShapeColored.cs in the latest 10.0.0 package. Please let us know if you need more info. Thanks.
     
    DragonCoder likes this.
  43. apparition

    apparition

    Joined:
    Jan 11, 2012
    Posts:
    104
    I updated the 2D Sprite Shape package in my project from 8.0.0 to 9.0.2 and I found a small bug with the LegacyCollider class (from the Sprite Shape Extras sample package).

    LegacyCollider now generates wonky results around corners. The issue is probably related to this fix in 9.0.2:
    • DANB-328 Fix case where BezierUtility.BezierPoint function parameters are not in the right order
    I was able to fix it by updating the order of arguments used in the BezierUtility.BezierPoint call in LegacyCollider.SampleCurve.

    The fix is simply changing this:
    Code (CSharp):
    1. Vector3 newPoint = BezierUtility.BezierPoint(startPoint, startTangent + startPoint, endTangent + endPoint, endPoint, t) * s_ClipperScale;
    To this:
    Code (CSharp):
    1. Vector3 newPoint = BezierUtility.BezierPoint(startTangent + startPoint, startPoint, endPoint, endTangent + endPoint, t) * s_ClipperScale;
     
    Venkify likes this.
  44. apparition

    apparition

    Joined:
    Jan 11, 2012
    Posts:
    104
    The LegacyCollider component handles this correctly! Venkify posted some info about this component here:
    https://forum.unity.com/threads/spriteshape-preview-package.522575/page-6#post-4479055

    You can find it in the Sprite Shape Extras sample for the 2D Sprite Shape package.
     
    PhantasmicDev and Venkify like this.
  45. wedgiebee

    wedgiebee

    Joined:
    Aug 9, 2016
    Posts:
    37
    Hi @Venkify, just checked out the samples in 10.0.0! Based on the previous replies I had interpreted that there would be examples for how to use Sprite Shape custom geometry generation specifically to generate SpriteShape interiors. Do you know of any examples of that that can be found?
     
  46. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    605
    A sample script for custom generation is added under Samples/Scripts/SpriteShapeColored.cs in the latest 10.0.0 package. Please let us know if you need more info. Thanks.
     
    wedgiebee likes this.
  47. wedgiebee

    wedgiebee

    Joined:
    Aug 9, 2016
    Posts:
    37
    Hey @Venkify! Sorry for retreading this topic, I think there's a slight misunderstanding. I'm looking for a sample that shows how to "invert" a sprite shape to generate an interior space, like is achieved in this link (https://forum.unity.com/threads/sprite-shape-interiors.1275836/#post-8100278). However, you mentioned it would be possible to do it using custom geometry generation, and I was hoping there would be an example that demonstrates that.

    I have looked at the SpriteShapeColored sample in 10.0.0, but changing the color of a sprite shape is a very different task from generating an interior space, so as someone who isn't familiar with the jobs system yet, the example doesn't get me much closer to achieving the desired effect.

    Totally understand if creating a sample that generates an interior space isn't planned, but just clarifying that interior-space-generation specifically is the type of example I had thought would be included. Thanks for your help either way!
     
  48. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    605
    Hi @wedgiebee,
    The idea behind the feature is to allow users to add custom scripts that allows over-riding some data on the generated geometry or completely override the entire geometry for SpriteShape. This pretty much allows infinite customizations to SpriteShape.
    Regarding more samples. we will consider adding most frequently ones to Samples in upcoming versions. Thanks.
     
    wedgiebee likes this.