Search Unity

SpriteShape Preview Package

Discussion in '2D Experimental Preview' started by rustum, Mar 19, 2018.

  1. dquek

    dquek

    Unity Technologies

    Joined:
    Apr 17, 2018
    Posts:
    41

    Hi! :)

    Do feel free to describe or report bugs here!
    We usually check back here often and do internal investigations on Bugs or issues.

    Alternatively, you can also file a bug report with a repro project through = Unity > Help > Report a Bug...
    This helps us debug issues faster.

    =============

    Looking at your project, it seems that your SpriteShape is missing a SpriteShape profile.
    You will need to add a SpriteShape profile with a fill texture to Render the SpriteShape properly in build.

    You can find out more on how to use SpriteShape in the Docs here:
    https://docs.unity3d.com/Packages/com.unity.2d.spriteshape@1.0/manual/index.html
     
  2. Paprik

    Paprik

    Joined:
    May 25, 2014
    Posts:
    7
    Hi,
    after upgrading to Unity 2019.1.1 and even after upgrading SpriteShape to the latest version, it seems to cause huge FPS drops whenever a SpriteShape object is in the scene.

    Is this a known issue? Do we need an extra step to upgrade SpriteShape properly?

    Thanks for any advice
     
  3. Paprik

    Paprik

    Joined:
    May 25, 2014
    Posts:
    7
    This is what it looks like in the profiler:
    upload_2019-5-13_17-35-51.png
     
  4. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    175
    Is this a known issue?
    We are fixing a related bug for GC alloc. However we want to take a look at FPS drop you mentioned. Please let us know the version of package and please send us a sample project.

    Do we need an extra step to upgrade SpriteShape properly?
    No additional setup needed.

    Please do report a bug with a sample repro project. Thanks.
     
  5. ai_ayarger

    ai_ayarger

    Joined:
    Jan 17, 2019
    Posts:
    1
    I apologize if I'm missing something simple-- The 2D SpriteShape package does not appear in package manager for 2019.2.0b (https://i.imgur.com/xMfeYHk.png). I have not yet installed the package.


    Thank you!

    Edit: Solved. My apologies-- Forgot to enable preview packages in the settings.
     
  6. milanhenkrich

    milanhenkrich

    Joined:
    Jul 26, 2018
    Posts:
    10
    Hello, I would like to ask - is there any way how to achieve scrolling of the closed sprite shape?
    Something like for renderer: renderer.material.mainTextureOffset = offset.
    I would like to achieve scrolling of force field (arrows) in 2D top view game.
     
  7. Kruczek

    Kruczek

    Joined:
    Mar 7, 2015
    Posts:
    3
    Hi, I've updated Unity to 2019.1.3f1 and noticed the bevel options are no longer availabe. Is this intended?

    no_bevel.PNG no_bevel2.PNG packagemanager.PNG
     
  8. Kruczek

    Kruczek

    Joined:
    Mar 7, 2015
    Posts:
    3
    Another question if I may, is it possible to create shapes with "holes" in them? Something similar to the following, withouth the "connecting edge".
    hole.PNG
     
  9. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    175
    @milanhenkrich
    This can be done with Shaders. A video to demonstrate the idea follows. Also attached is a simple demo to achieve scrolling.

     

    Attached Files:

    Last edited: May 30, 2019
    OscarLeif likes this.
  10. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    175
    @Kruczek
    Yes, this is intentional. Since 2.0.0-preview.7 we have added Mirrored and Non-mirrored tangent mode support which has made Bevel options more or less redundant. One the sample scenes (SimpleDrawScene) has also been modified for this change.

    Yes, with some tricks its possible for the use-case you described above. Use the null sprite feature to not set any sprite for a specific edge to achieve this. Video here:

     
    nosajtevol likes this.
  11. Kruczek

    Kruczek

    Joined:
    Mar 7, 2015
    Posts:
    3
    @Venkify

    Great! Thank you very much.
     
  12. kyuskoj

    kyuskoj

    Joined:
    Aug 28, 2013
    Posts:
    10
    Hi, Are these states intended? (2.0.0 preview 8)
    I am confused because these options are not activated in Sprite Renderer.
    upload_2019-6-2_19-50-2.png
     
  13. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    175
    It seems that the SpriteShape Package did not import properly. May I know the Unity version you are using ?

    fyi, the latest compatible versions as of this post is
    Unity Editor version => latest SpriteShape version.
    2018.1, 2018.2, 2018.3, 2018.4 => 1.0.14-preview.2
    2019.1 => 2.0.0-preview.8
    2019.2 => 2.1.0-preview.2
     
    Last edited: Jun 4, 2019
  14. gregtom7

    gregtom7

    Joined:
    Oct 24, 2015
    Posts:
    3
    Hi @Venkify!

    We are using 2D SpriteShape for our project for a long time, and we have noticed some bugs (maybe there're bugs, but not sure):
    We're creating SpriteShapes during runtime, and we get this error almost everytime:
    ArgumentException: shapeParams.splineDetail (0) must be within 4 - 32.
    This is weird, since when we print the spriteShapeController.splineDetail, it will be 4, 8 or 16 based on the editor settings of the SpriteShapeController's selected spline detail component (low, medium, high). Although it's value is within 4-32 everytime, it still gives the error. Although both values are meant the same (tessellation of the spline).

    We put the BakeMesh() method into a try-catch block, but sometimes the game freezes out, when the mesh is being created.

    We are using 2D SpriteShape 1.0.1.4 (for Unity 2018.4.0f1), and we are seeing the 2.0.0 for Unity 2019 maybe solved this problem (https://docs.unity3d.com/Packages/com.unity.2d.spriteshape@2.0/changelog/CHANGELOG.html, in here 1.1.0 mentions "Spriteshape tessellation code is re-implemented in C# Jobs and utilizes Burst for Performance."), which is in Unity 2019, but we can't switch to Unity 2019 for multiple dependencies.

    What can we do about this error and/or the freezing? Can we somehow use a newer SpriteShape version for Unity 2018.4.0?


    There's another, rare error we sometimes get (ArgumentException: Internal error: Point too close to neighbor), but it's confusing for me about what means "too close". Maybe it can be relative, but if it's a relative thing, then it maybe depends on the width of the curve. Is there a good equation or a minimum point distance we need to use?
    Because of it's very rare, I don't think it's causing the freezing of the build, but we don't know.
     
  15. dquek

    dquek

    Unity Technologies

    Joined:
    Apr 17, 2018
    Posts:
    41
    Hi there!

    Could you send in a slice of you project for us to take a look and investigate?

    We will try to reproduce and fix it.

    ====
    Alternatively, you can also file a bug report with a repro project through = Unity > Help > Report a Bug...
    This helps us debug issues faster.
     
  16. dquek

    dquek

    Unity Technologies

    Joined:
    Apr 17, 2018
    Posts:
    41
  17. nosajtevol

    nosajtevol

    Joined:
    Jun 28, 2012
    Posts:
    211
    Wondering if anyone knows how to inset the vertices of a spriteshape at runtime?
     
  18. nosajtevol

    nosajtevol

    Joined:
    Jun 28, 2012
    Posts:
    211
    Never mind, figured it out. Here's a script that will allow you to expand or inset the vertices of a spriteshape at runtime:

    Code (CSharp):
    1.  
    2.     public void InsetVertices(SpriteShapeController spriteShape, float offsetDistance)
    3.     {
    4.         int totalSplinePoints = spriteShape.spline.GetPointCount();
    5.         Spline spl = spriteShape.spline;
    6.  
    7.         for (int i = 1; i < spl.GetPointCount() - 1; ++i)
    8.         {
    9.             Vector3 lt = Vector3.Normalize(spl.GetPosition(KeepIndexWithinRange(i-1,totalSplinePoints -1)) - spl.GetPosition(i));
    10.             Vector3 rt = Vector3.Normalize(spl.GetPosition(KeepIndexWithinRange(i+1, totalSplinePoints -1)) - spl.GetPosition(i));
    11.             float a = Angle(Vector3.up, lt);
    12.             float b = Angle(lt, rt);
    13.             float c = a + (b * 0.5f);
    14.             if (b > 0)
    15.                 c = (180 + c);
    16.  
    17.  
    18.             Vector3 dir = Quaternion.AngleAxis(c, Vector3.forward) * Vector3.up;
    19.             spriteShape.spline.SetPosition(i,spl.GetPosition(i) + (dir * offsetDistance));
    20.         }
    21.     }
    22.  
    23.  
    24.     float Angle(Vector3 a, Vector3 b)
    25.     {
    26.         float dot = Vector3.Dot(a, b);
    27.         float det = (a.x * b.y) - (b.x * a.y);
    28.         return Mathf.Atan2(det, dot) * Mathf.Rad2Deg;
    29.     }
    30.  
    31.     int KeepIndexWithinRange(int i, int total)
    32.     {
    33.         if (i < 0)
    34.         {
    35.             i = total;
    36.             return i;
    37.         }
    38.  
    39.         if (i > total)
    40.         {
    41.             i = 0;
    42.             return i;
    43.         }
    44.  
    45.         return i;
    46.     }
    If you want to inset, simply set the offset distance negative. Expand is positive. Code based on the Sprinkler script.
     
    Last edited: Jun 4, 2019
  19. nosajtevol

    nosajtevol

    Joined:
    Jun 28, 2012
    Posts:
    211
    Any chance you have the script for this? Trying to figure this out at the moment. Thanks!
     
  20. alanmthomas

    alanmthomas

    Joined:
    Sep 7, 2015
    Posts:
    136
    Which script are you referring to?
     
  21. kyuskoj

    kyuskoj

    Joined:
    Aug 28, 2013
    Posts:
    10
    Thanks. It was 2019.1.0f2 with 2.0.0-preview.8
    and It is still being reproduced.
     
  22. nosajtevol

    nosajtevol

    Joined:
    Jun 28, 2012
    Posts:
    211
  23. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    175
    Hi,
    We published a new version '2.1.0-preview.7' (compatible with 2019.2 and above) of SpriteShape. Apart from bugfixes we have added a few features that hopefully makes editing SpriteShapes better.

    Variant Selector:
    We have added a Sprite-Selector UI in the Inspector so selecting a variant Sprite for an Edge is easier. The Inspector will also update its selection as you Edit the Shape. A demonstration video here:



    Multi-Edit:
    We also have added the ability to move/edit multiple points from multiple spriteshape objects. A demonstration video here:

     
    EvOne and nosajtevol like this.
  24. nosajtevol

    nosajtevol

    Joined:
    Jun 28, 2012
    Posts:
    211
    Awesome! Great work guys!
     
  25. BTStone

    BTStone

    Joined:
    Mar 10, 2012
    Posts:
    1,064
  26. mimminito

    mimminito

    Joined:
    Feb 10, 2010
    Posts:
    779
    Is it possible to generate points at regular intervals along the spline? To say spawn trees every 'x' distance along the spline itself?
     
    nosajtevol likes this.
  27. dquek

    dquek

    Unity Technologies

    Joined:
    Apr 17, 2018
    Posts:
    41
  28. pastaluego

    pastaluego

    Joined:
    Mar 30, 2017
    Posts:
    49
    Anybody have any techniques on how to set up setup seamless fill to edge transitions for brick or stone walls using SpriteShape? Here's an example of what I'm trying to accomplish:
    upload_2019-6-11_11-11-26.png
    I can't seem to think of a good way to do it since the filltexture bricks need to seamlessly line up both horizontally and vertically with the edgetexture bricks. For more natural textures it's as simple as feathering the bottom edge of the sprite, but for more man-made textures there's less leeway.

    There are a couple cheats I can do to make it look somewhat passable like giving the sprite outline of the side edge sprite extra blank space to help line it up with the fill, but they're extremely limited and not reliable. I was hoping someone had some secret technique that I haven't thought of. But something tells me I'm going to just have to make very precise edges sprites crafted specifically to match the fill exactly and and meticulously shape it in a limited way in order to make it seamless.
     
    Last edited: Jun 11, 2019
  29. nosajtevol

    nosajtevol

    Joined:
    Jun 28, 2012
    Posts:
    211
    Hey guys! Just want to share how far I've come using the Sprite Shape Preview Package for procedural generation. All of the objects in the game are being procedural generated along the spline. Also the black cover on the bottom of the ground is copied from the ground sprite shape, with the vertices inset to make it go "into" the ground. There's a few helper functions that could be useful out the gate (like insetting vertices, getting normal of points, getting points at random intervals along the spline, etc.) but overall it's a great basis to develop onto.

    https://www.instagram.com/p/Byl9ogoni5n/
     
    Venkify and rustum like this.
  30. Discipol

    Discipol

    Joined:
    May 6, 2015
    Posts:
    36
    I can't see the link (Broken?). I am doing procedural generated race tracks using SpriteShape and I can't determine when the SpriteShape is finished generating. Any ideas nosajtevol how to have a... "on complete callback" or something?
     
  31. nosajtevol

    nosajtevol

    Joined:
    Jun 28, 2012
    Posts:
    211
    Not sure why you can't see it, it works for me! Here's a relink just in case:

    https://www.instagram.com/p/Bynj4mpHzyW/

    I'm not sure, sorry. I'm actually not generating the ground itself, I'm populating objects on the spline.
     
  32. Discipol

    Discipol

    Joined:
    May 6, 2015
    Posts:
    36
    Instagram was down at the time I clicked :)) I dug deeper into my problem and it seems if the camera does not have the SpriteShapeRenderer in its cone, it will set isVisible of the Renderer to false, and NOT trigger OnWillRender in the controller.

    A dumb fix is to make sure the camera is looking at the empty SpriteShapeRenderer till it starts generating the mesh. I wish I could have it always render no matter of the camera. Anybody know how?
     
  33. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    175
  34. Discipol

    Discipol

    Joined:
    May 6, 2015
    Posts:
    36
    Thank you for replying! I am using 2019.1.7f1, with 2.0.0-preview.8 (2019.1).
    I tried calling BakeMesh, I got a lot of errors regarding the Profiler having a Begin call and NOT having an end call OR something about NativeArrays OR calling a previous Job complete before starting another one.

    The workaround I have is forcing the camera to LOOK at the SpriteShape and checking if the collider attached has any points. If it has points, then I consider it rendered and then I move the camera on my main actor.

    If you tell me 2.1.0-preview7 is a superior version, I can upgrade to 2019.2 (if that is stable enough for production stage). All my code is self-made and I don't use any lib except unity stuff.
     
  35. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    175
    @Discipol

    You can manually schedule a BakeMesh and ensure its completion as follows :

    var jobHandle = GetComponent<SpriteShapeController>().BakeMesh();
    jobHandle.Complete();

    An example script to force SpriteShape generation is as follows:

    Code (CSharp):
    1. public class ForceGenerate : MonoBehaviour
    2. {
    3.     // Start is called before the first frame update
    4.     void Start()
    5.     {
    6.         var jobHandle = GetComponent<SpriteShapeController>().BakeMesh();
    7.         jobHandle.Complete();
    8.     }
    9.     // Update is called once per frame
    10.     void Update()
    11.     {
    12.      
    13.     }
    14. }
    As SpriteShape generation is fast for most cases and to make efficient use of memory its only generated when visible. However using the above script you can generate it when required even if its not visible. Please let us know if this works.

    Please check Assets\Unity Technologies\2D Sprite Shape\Extras\Scenes\SprinklePrefabs.unity in the Extras which contains a simple sample. You can import Extras/Samples from the package that contains some useful scripts using PackageManager UI:

    Package_Extras.png
     
    Discipol and nosajtevol like this.
  36. office_gamelab

    office_gamelab

    Joined:
    Nov 27, 2017
    Posts:
    6
    Hy. We are working on a project in Unity 2018.4.0f1 and using SpriteShape 1.0.14.
    (This is the log term support so we can't really change the Unity version)

    We have a big problem with Playstation 4 builds:
    This example scene looks fine on most of the platforms, but on PS4 only the first part of the edge appears.
    With not filled profils it worked fine on every platform.
    Untitled.png
    Can somebody help us with this issue?
     
  37. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    175
    @office_gamelab Thanks for reporting. This has already been fixed in 2019.3 and should be available in the next alpha. We have also backported the fixes for 2019.2 and 2018.4 and these should be available in their respective upcoming releases soon. I will post an update once they are available.

    Its also reported here : https://forum.unity.com/threads/sprite-shape-artifacts-on-ps4.670465/
     
    office_gamelab likes this.
  38. mimminito

    mimminito

    Joined:
    Feb 10, 2010
    Posts:
    779
    This only gets the existing points along a spline, does not let me position along the spline at any "percentage". For example if I wanted to move a gameobject along the spline it would be good to be able to calculate its required position based on a percentage from the start.
     
  39. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    175
    To get any position between 2 neighbouring points in the spline with a delta T, please use the (GetPositionAtBezierT) from the following snippet:

    Code (CSharp):
    1.     static float2 BezierPoint(float2 st, float2 sp, float2 ep, float2 et, float t)
    2.     {
    3.         float2 xt = new float2(t);
    4.         float2 nt = new float2(1.0f - t);
    5.         float2 x3 = new float2(3.0f);
    6.         return (sp * nt * nt * nt) + (st * nt * nt * xt * x3) + (et * nt * xt * xt * x3) + (ep * xt * xt * xt);
    7.     }
    8.  
    9.     Vector3 GetPositionAtBezierT(int cpIndexFrom, int cpIndexTo, float t)
    10.     {
    11.         SpriteShapeController ssc = GetComponent<SpriteShapeController>();
    12.         Spline spl = ssc.spline;
    13.         float2 bp = BezierPoint(new float2(spl.GetRightTangent(cpIndexFrom).x + spl.GetPosition(cpIndexFrom).x, spl.GetRightTangent(cpIndexFrom).y + spl.GetPosition(cpIndexFrom).y),
    14.             new float2(spl.GetPosition(cpIndexFrom).x, spl.GetPosition(cpIndexFrom).y),
    15.             new float2(spl.GetPosition(cpIndexTo).x, spl.GetPosition(cpIndexTo).y),
    16.             new float2(spl.GetLeftTangent(cpIndexTo).x + spl.GetPosition(cpIndexTo).x, spl.GetLeftTangent(cpIndexTo).y + spl.GetPosition(cpIndexTo).y), t);
    17.         return new Vector3(bp.x, bp.y, 0);
    18.     }
    Also attached is a modified Sprinkler script.
     

    Attached Files:

    Last edited: Jun 19, 2019
    nosajtevol likes this.
  40. mimminito

    mimminito

    Joined:
    Feb 10, 2010
    Posts:
    779
    Brilliant, thank you!
     
  41. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    175
    office_gamelab likes this.
  42. milanhenkrich

    milanhenkrich

    Joined:
    Jul 26, 2018
    Posts:
    10
    Thank you for reply Venkify, but I am looking more on something like: scrolling of inside texture filling of closed sprite shape. I think this is very challenging to achieve
     
  43. jbarba109

    jbarba109

    Joined:
    Dec 16, 2014
    Posts:
    5
    Greetings

    I know I should not be doing this, but I'm testing sprite shapes with 2019.2.0b7 (yep, the Beta) and I'm facing some issues
    • For preview.2 - 2.1.0 It works almost all fine, except that the fill material is always over the borders, here is an example of what happens using the example provided by the package https://i.imgur.com/zNOakTc.png
    • For preview.6 - 2.1.0 and further, I simply can't use any of it the project: its unable to find lots of types, classes and namespaces inside UnityEditor.U2D, this is an screenshot using preview.10 https://i.imgur.com/zrjYp4i.png, I'm not sure if I should install another package
    I'm doing this test using the beta because I'm working alongside the new 2D renderer and the 2D lights, that part works like a charm!
     
  44. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    175
    @jbarba109
    In case of 2.1.0-preview.10, we are aware of these errors due to Path Editor present both in embedded form within LWRP and as a separate package and ends up in conflicts. We are in the process of fixing it and will publish a new version of LWRP/Path asap. Will update this thread once its available.

    Regarding the issue on 2.1.0-preview.2, is that using Sprites-Default shader for the Renderer ? Could you please post a sample repro project so we can get more info and take a look ?
     
  45. jbarba109

    jbarba109

    Joined:
    Dec 16, 2014
    Posts:
    5
    @Venkify
    Thanks for your update

    I'll try to have a sample from my project asap, however I did tried to change the shader to Sprites-Default, it didn't work, also as I mentioned I used the Sample Project that the package manager provides for this package, and it also happens there (see the link https://i.imgur.com/zNOakTc.png for a screenshot, this is not a sprite shape from my project, but from the sample scene), I might need to try a brand new project with preview.2 using the samples to see if it happens in a new project
     
  46. jbarba109

    jbarba109

    Joined:
    Dec 16, 2014
    Posts:
    5
    @Venkify ok I tried with a new project, and the sprite shapes in the test project the package provides looks as expected, with the fill material behind the borders

    Do you know what can I do to make it look correctly in my project? The strangest thing is: even if I import the package test project in the project I'm working on, the fill material stays at front, it seems to be something in my project that affects all sprite shapes, even the new ones...
     
  47. jbarba109

    jbarba109

    Joined:
    Dec 16, 2014
    Posts:
    5
    I found the issue... I also was testing the new 2d lighting system, with uses a custom LWRP asset, switching back to a normal render pipeline (none) gets the sprite shapes to work as expected. Also, I created another LWRP that doesn't use the custom renderer, but Forward Renderer, without luck
     
  48. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    175
    Thanks for the update. Could you please submit a sample project/scene so we can take a deeper look at this issue ?
     
  49. jbarba109

    jbarba109

    Joined:
    Dec 16, 2014
    Posts:
    5
    @Venkify here you go https://github.com/HakS/SpriteShapeBeta7 its brand new with the example scenes taken from the sprite shape package and the render pipeline already set up (the bug happens even without the 2D renderer, just the forward renderer), the bug should be there immediately after you open the Platformer.unity scene
     
  50. AVOlight

    AVOlight

    Joined:
    Apr 15, 2014
    Posts:
    401
    hi, i'm a struggling indie dev looking for a way to monetize some of my work

    a while ago i developed an alternative shape triangulation method that's done in the shader and I'm wondering if I can sell it to Unity? (compatible with #pragma target 2.0)
    it makes it practical and performant for run-time dynamic shapes that can be animated through Unitys native animation workflows.

    here's a vid of the shader in action

    it was my first game i made as i learned Unity and coding so will need to clean things up if there's interest for it;

    please let me know if any body has any ideas on how to best monetize the code without any marketing budget (which i'd probably need for the asset store)