Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Official SpriteShape Preview Package

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

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

    WoelieWoel

    Joined:
    Apr 18, 2018
    Posts:
    3
    Silly me, yes, that worked perfectly. :oops: Thanks.
    Been playing with it for a while, looks really good. Going to use this alot. :)
     
  2. smi_shadhin

    smi_shadhin

    Joined:
    Jun 20, 2016
    Posts:
    1
  3. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    638
    @smi_shadhin
    To set Pixels Per Unit for Fill texture, please specify it in SpriteShape Asset. Since the fill texture is basically a Texture2D object, Pixels Per Unit from the Texture Importer (if imported as Sprite) is not used for Fill texture.
    For sprites used in Angle Range and Corners, since Inputs are sprites, original Pixels Per Unit specified while importing them as sprites is used.
     
  4. summerian

    summerian

    Joined:
    Jul 6, 2014
    Posts:
    140
    This doesn't seem to be in the 2018.1f package manager?
     
  5. Gamingbir

    Gamingbir

    Joined:
    Apr 1, 2014
    Posts:
    194
    is it available via unity asset store or something? Does not seem to be in unity by default in 2018 version.
     
  6. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    638
    Please check here :
    https://github.com/Unity-Technologies/2d-spriteshape-samples
    for more info on using the package.
     
  7. Brumby

    Brumby

    Joined:
    Sep 8, 2014
    Posts:
    16
    Is there any way to reduce draw calls? If I duplicate the same SpriteShape on scene it will take up more draw calls. I'm worrying about mobile performance.
     
  8. Gamingbir

    Gamingbir

    Joined:
    Apr 1, 2014
    Posts:
    194
  9. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    638
    Could you share a sample scene or use-case ? It would be helpful to investigate / provide feedback.

    This is available as a package in 2018.1 Please check the Github sample project page for detailed Info. (https://github.com/Unity-Technologies/2d-spriteshape-samples)

    Also please check (https://github.com/Unity-Technologi...ples/blob/master/Documentation/SpriteShape.md) for detailed documentation.
     
  10. Brumby

    Brumby

    Joined:
    Sep 8, 2014
    Posts:
    16
    This is a screenshot from "CastleJumper" example scene. Why does the dynamic batching not work on the multiple duplicated objects with the same material ?
     

    Attached Files:

    Last edited: May 7, 2018
  11. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    638
    Thanks. DynamicBatching/Instancing is not yet supported in SpriteShapeRenderer. However we will investigate optimizing for use-cases where dynamic batching is desirable. Will keep this thread posted.

    (Please note: Most common uses of SpriteShapes (including ones in the sample projects) have > 300 vertex count in high quality https://docs.unity3d.com/Manual/DrawCallBatching.html).
     
  12. Ccrawler

    Ccrawler

    Joined:
    Feb 8, 2017
    Posts:
    9
    Amazing tool!

    A feature I would love to have is the ability to control sprites indexes not just by vertices but by segments as well. A sprite index randomizer would be good too. Here's an example of what I mean in ferr2D:

     
    Esk4 likes this.
  13. CosmicBoy

    CosmicBoy

    Joined:
    Apr 16, 2014
    Posts:
    35
    This is fantastic, great work! :)

    I have a question, why is the fill texture a texture instead of a sprite? When I try to use the standard shader material we use for our spritesheets on the spriteshape, there is no way to include the texture required for the fill slot into the spritesheet used in the material as the fill slot doesnt support sprites. You can only use one material on the spriteshape, so it defaults to using the entire spritesheet as the fill layer. Everything else works perfect bar the fill layer problem i'm having.

    Or is there something I am missing?

    Thank you!

     
  14. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    638
    Thanks for the feedback. The Fill texture requires Wrap mode set to repeat to get automatic tiling. Hence it cannot be part of Atlas/SpriteSheet either. Angle-Range/Corner sprites do not need this wrap mode as proper UV is generated while tessellation.

    Thanks for the feedback. We will investigate this and update this thread.
     
    Ccrawler likes this.
  15. UmbrellaGamesLLC

    UmbrellaGamesLLC

    Joined:
    Oct 11, 2017
    Posts:
    7
    Hi @Venkify ,

    There's a small bug/annoyance: When you change a sprite's settings (pixels per unit, sprite shape, etc) the SpriteShape does not get redrawn until you edit it.

    I also have a question. I would like to move something along the spline, with the controller's current detail level (or even a custom detail level). Is there an easy way to do this, or will I have to dive into the scripts to figure it out? A Spline.Evaluate(int pointIndex, float progress, int detailLevel) method might be a useful addition.

    It might even be a good idea to move the Spline class to core Unity at some point, as it's likely to be useful for many uses besides SpriteShape.
     
  16. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    638
    Thanks for the feedback.

    This has been fixed and will be available in the next version of the package.

    UnityEngine.U2D.BezierUtility.BezierPoint is a public function in the package that can be used to generate the spline path.
    Please check function void SampleCurve(Vector3 startPoint, Vector3 startTangent, Vector3 endPoint, Vector3 endTangent, ref List<IntPoint> path) in SpriteShapeController.cs for sample usage.
     
  17. UmbrellaGamesLLC

    UmbrellaGamesLLC

    Joined:
    Oct 11, 2017
    Posts:
    7

    Thanks - I already figured that out, but I still think a helper method that passes along the right stuff would be useful in the package.

    Here's how I did it, could be easily adapted :

    Code (CSharp):
    1.     public static Vector3 FindPoint(int index, float progress) {
    2.         while (progress >= 1) {
    3.             progress--;
    4.             index++;
    5.         }
    6.         while (progress < 0) {
    7.             progress++;
    8.             index--;
    9.         }
    10.  
    11.         index = Mod(index, instance.spriteShapeController.spline.GetPointCount());
    12.  
    13.         Vector3 startPoint = instance.spriteShapeController.spline.GetPosition(index);
    14.         Vector3 endPoint = instance.spriteShapeController.spline.GetPosition(Mod(index + 1, instance.spriteShapeController.spline.GetPointCount()));
    15.         Vector3 startTangent = instance.spriteShapeController.spline.GetRightTangent(index);
    16.         Vector3 endTangent = instance.spriteShapeController.spline.GetLeftTangent(Mod(index + 1, instance.spriteShapeController.spline.GetPointCount()));
    17.         return BezierUtility.BezierPoint(startPoint, startPoint + startTangent, endPoint + endTangent, endPoint, progress);
    18.     }
     
  18. gOzaru84

    gOzaru84

    Joined:
    Oct 1, 2016
    Posts:
    8
    This is marvelous.
    I hope there is documentation about how to use Sprite Shape Profiles correctly.

    I just tested the collider.
    It doesn't work. I thought it supposed to create collider automatically, right?
    What does the meaning of collider?
    I added physics2D manually and it is now better.

    When will this preview become extension/package?
     
  19. UmbrellaGamesLLC

    UmbrellaGamesLLC

    Joined:
    Oct 11, 2017
    Posts:
    7
    You need to add a polygon collider yourself, but the spriteshape can update it automatically with the given settings.
    Note that when you check "update collider" it does not update it automatically when changing the shape through script.
     
    gOzaru84 likes this.
  20. DoYouRockBaby

    DoYouRockBaby

    Joined:
    May 21, 2018
    Posts:
    9
    Great feature, i realy love it !

    I don't understand how the corner textures mapping is working, i have an interval between my textures and i dont manage to ajust it to have somethings with nice look.

    Capture.PNG

    For now, i dont have any problem with the tool.
    A little feature that would be nice in the final version : When we update the sprite in the sprite editor, the spriteshape is not updated, i have to restart unity everytime i ajust my texture, it would be nice if it was done automaticaly.
     
  21. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    Hello,

    I had just downloaded the package and I'm having an hard time trying to add a collider. I mean, I can add an edge collider for instance, but it will appear as a straight line and I will have to "map" it along the SpriteShape which can be a very tedious task. I tried to add a composition collider but the "generate" button does not generate anything.

    So, what is the best way to add a collider to a SpriteShape ?

    Thanks
     
  22. DoYouRockBaby

    DoYouRockBaby

    Joined:
    May 21, 2018
    Posts:
    9
    Use a polygon collider and check "Update Colider" in the sprite shape controller settings.
     
  23. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    Thanks !
     
  24. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    638
    Thanks for the feedback.
    This has been fixed. We will be releasing a new version of the package with fixes for a set of reported bugs.

    The requirements for corner sprite usable in a point are 1) Neighbor points must also be linear too.2) Angle not too acute where it automatically reverts to non-corner sprite.
    If the parameters are met and if it still do not align, could you please submit a bug along with the sample scene/assets p[lease ? Will take a look asap.
     
    Last edited: May 24, 2018
  25. Gamingbir

    Gamingbir

    Joined:
    Apr 1, 2014
    Posts:
    194
    Hi, I am trying to create a platform with this tileset. The tiles are 64x64.
    Top row:
    Bottom row:

    I am getting this atm. I followed the documentation.


    Thanks for the help. I was also wondering if there is going to be some sort of video tutorial on it?
     
  26. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    638
    @Gamingbir I think you are trying to setup corner sprites. Please take a look at Castle-Jumper scene in the Github 2d-spriteshape-samples. Check CastleWallFill Spriteshape Asset for a usage sample. Basically you will need to utilize/set the 8 Corner Sprites.
     
  27. Robiwan

    Robiwan

    Joined:
    Dec 29, 2013
    Posts:
    92
    This looks really cool, could it be used to have 2d ropes?

    Ive been doing some testing with the hinge joints which works well for a chain, but once you want HD rope which has no natural "chains" I need something to smooth out for each node of the hinge joint.

    Ideas and how to implement would be greatly appreciated.
     
  28. makadi-milan

    makadi-milan

    Joined:
    Dec 20, 2014
    Posts:
    1
    If i also insert some points by script the SpriteShapeRenderer has a "Center: (0.0, 0.0, 0.0), Extents: (0.0, 0.0, 0.0)" boundary therefore it doesn't draw anything in the game view until i double click on the gameobject in the hierarchy while the scene view is actvie.
    I also tried to call a BakeMesh() after the InsertPointAt() function call, but i get "Assertion failed: Assertion failed on expression: '!m_HasActiveGeneratorJob'
    UnityEngine.U2D.SpriteShapeController:OnWillRenderObject()" errors.
    it ocures in Unity 2018.1.2f1, windows10
     
    Last edited: May 30, 2018
  29. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    638
    @makadimilan Ensure that SpriteShape has at-least 2 points. You can then add/remove points. The points cannot be too close to each other. BakeMesh need not be called at all as any change to the Spline should regenerate SpriteShape.
     
  30. makadimilan

    makadimilan

    Joined:
    Sep 27, 2017
    Posts:
    1
    Thank you for your response. I find a solution, if any camera looks at the origo during the generation, it works fine.
     
  31. Gamingbir

    Gamingbir

    Joined:
    Apr 1, 2014
    Posts:
    194
    I was wondering what term is used to call this technique. Is it sprite deformation?
     
  32. CosmicBoy

    CosmicBoy

    Joined:
    Apr 16, 2014
    Posts:
    35
    So is there any way to use a custom material and have the sprite shape be fully functional including a fill texture?
     
  33. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    638
    Yes, you should be able to use Materials compatible to SpriteRenderer with SpriteShapeRenderer as well.
     
  34. rushk1

    rushk1

    Joined:
    Sep 24, 2017
    Posts:
    39
    Hello

    I have (hand drawn) images whose shape I want to use to create GameObjects with the same shape using SpriteShape , to save on file size.

    How can I do this?

    a. I do not know how to convert the vertices of the source image which are a Vector2 array to Vector3 as required by the Spline.InsertPointAt method.

    b. I do not know how to Generate a new Object with the shape derived from the above vertices info. So I tried adding points to the spline of an existing GameObject with SpriteShapeController already attached using Spline.InsertPointAt but If i try a mock value of Vector3(3f, 4f,0f) I get the error
    ArgumentException: Internal error: Point too close to neighbor
    UnityEngine.U2D.Spline.InsertPointAt (Int32 index, Vector3 point)
    Unity/cache/packages/staging-packages.unity.com/com.unity.2d.spriteshape@1.0.10-preview.1/Runtime/Spline.cs:58)
    ShapeSource.Start () (at Assets/ShapeSource.cs:31)

    I have an image that I imported and got its vertices
    Code (CSharp):
    1. sourceSpriteRenderer = GetComponent<SpriteRenderer>();
    2.         sourceSprite = sourceSpriteRenderer.sprite;
    3.         Vector2[] sourceVertices = sourceSprite.vertices;
    4.  
    5. targetSprite= GameObject.Find("target");
    6. SpriteShapeController targetSpriteShapeController = targetSprite.GetComponent<SpriteShapeController>();
    7.      Spline targetSpline = targetSpriteShapeController.spline;
    8.  
    9.         Vector3 m_vector3 = new Vector3(3f, 4f,0f);
    10. targetSpline.InsertPointAt(targetSpline.GetPointCount(), m_vector3 );
    11.  
    I created an empty game object called "target", attached the SpriteShapeController and added 3 points to the Spline manually
    The First Point at Index 0 has Point Position (x=-12.90, y =0.95)
    The Second Point at Index 1 has Point Position (x=1, y=-3)
    The Third Point at Index 2 has Point Position (x=0.25, y=1.6)

    and tried to add a fourth point by script, but got the Internal error: Point too close to neighbor


    I am a complete beginner so apologies for the elementary questions.
     
    Last edited: Jun 14, 2018
  35. Igorexa

    Igorexa

    Joined:
    Sep 25, 2014
    Posts:
    23
    Hi,

    Thank you for great asset.

    Two problem i have :

    1. When i save scene i get error:
    Assertion failed: Assertion failed on expression: '!m_HasActiveGeneratorJob'
    UnityEngine.U2D.SpriteShapeController:BakeMesh(Boolean)
    SpriteShapeAssetPostProcessorHandler:OnPostprocessAllAssets(String[], String[], String[], String[]) (at /Users/igor/Library/Unity/cache/packages/packages.unity.com/com.unity.2d.spriteshape@1.0.10-preview.2/Editor/SpriteShapeAssetPostProcessorHandler.cs:18)
    UnityEditor.AssetPostprocessingInternal:postprocessAllAssets(String[], String[], String[], String[], String[])

    2. Sometime on some objects corners is not work. I switch Corner to Automatic/Disabled, try to remap corners in material - it is not help (Point and neighbors points are "Straight line from point to point" selected).

    How i can fix this problems?
     
  36. Jiraiyah

    Jiraiyah

    Joined:
    Mar 4, 2013
    Posts:
    175
    I know that this is still experimental development, but those who tried it, is this stable enough to integrate it into a production pipe line?
     
  37. Jiraiyah

    Jiraiyah

    Joined:
    Mar 4, 2013
    Posts:
    175
    @rustum
    heads up on 2018.2.0.x - Prefab preview :

    C:/Users/Alireza/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.2d.spriteshape@1.0.11-preview/Editor/SpriteShapeEditorUtility.cs(47,48): warning CS0618: `UnityEditor.PrefabUtility.GetPrefabType(UnityEngine.Object)' is obsolete: `Use PrefabTypeUtility GetType and GetPrefabInstanceStatus to get the full picture about prefab types'

    C:/Users/Alireza/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.2d.spriteshape@1.0.11-preview/Editor/SpriteShapeEditorUtility.cs(48,46): warning CS0618: `UnityEditor.PrefabType' is obsolete: `PrefabType no longer tells everything about prefab instance '

    C:/Users/Alireza/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.2d.spriteshape@1.0.11-preview/Editor/SpriteShapeEditorUtility.cs(48,81): warning CS0618: `UnityEditor.PrefabType' is obsolete: `PrefabType no longer tells everything about prefab instance '

    C:/Users/Alireza/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.vectorgraphics@1.0.0-preview.13/Runtime/SVGParser.cs(43,22): warning CS0618: `System.Xml.XmlReaderSettings.ProhibitDtd' is obsolete: `Use XmlReaderSettings.DtdProcessing property instead.'

    I know that version is experimental but a heads up for early adoption to their new API would be good.
    thanks
     
  38. JohnBrindle

    JohnBrindle

    Joined:
    Jan 3, 2014
    Posts:
    8
    Great cannot wait to play with this, but where are the samples you mentioned in the first post.
    I cannot find anything in the package!?
    JB
     
  39. Tona999

    Tona999

    Joined:
    Nov 18, 2015
    Posts:
    6
    Hey guys, do you think it's possible to get the sprite index of a precise point on the spline?
    I have a ball that bounces and I would like to know if it touches the red or the blue color (so sprite with index 0 or index 1) as you can see in the screenshot.

    Any ideas?
     

    Attached Files:

  40. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    638
    - When you insert points to SpriteShape ensure that the neighbor points are not too close to each other. Just skip the point and insert the next if its too close.

    - Thanks for the feedback. I believe this is fixed. Will update this thread with the version info soon.

    - Could you please post a sample scene/project ?

    - Thanks for the feedback. I believe we have tested this a lot with a number of use-cases and tests. We are just waiting for more feedback and inputs. We will fix the API warnings in the upcoming version.

    - Did you manage to get the package ? Please let us know if you need more info.

    - Narrow down the results to the nearest N points based on distance of each point to the Object. To find the closest point try using utility functions ClosestPointToSegment / ClosestPointOnCurve that can be found in Runtime\BezierUtility.cs (in the package). Please let us know if you need more info.
     
  41. Igorexa

    Igorexa

    Joined:
    Sep 25, 2014
    Posts:
    23
    I found the problem. If neighbor points has height not equal 1 - corner not shown. If points has different height - corner not shown.
     
  42. Tona999

    Tona999

    Joined:
    Nov 18, 2015
    Posts:
    6
    I just noticed that it's not possible to use the shape generated as a sprite mask because the sprite mask requires indeed a sprite, and not a sprite shape.

    Is the shape baked into a sprite once the build is complete?
    Is it possible to access the sprite generated by the sprite shape in a Start() function and then assign the sprite to a sprite mask?

    Thanks.
     
  43. sharksharkshark

    sharksharkshark

    Joined:
    Apr 27, 2015
    Posts:
    13
    I'm seeing a bug where calling SetPosition or InsertPointAt doesn't update the actual mesh at runtime for WebGL builds. Is this a known issue and/or is there a workaround?
     
    Last edited: Jul 10, 2018
  44. Matthew-Schell

    Matthew-Schell

    Joined:
    Oct 1, 2014
    Posts:
    238

    Just wanted to say that this bug still seems to persist in 2018.15f1, had same happen to me. Thanks for posting your fix @liliththepale.
     
  45. SebaldDM13

    SebaldDM13

    Joined:
    Mar 3, 2018
    Posts:
    1
    Thank you for the preview of SpriteShape.

    After adding points in a SpriteShape to form the outline of a lowercase 'e' (image below), what would be the way to add points to form a transparent hole in the letter?

    Sprite Shape Screenshot.png
     
  46. ChrisIceBox

    ChrisIceBox

    Joined:
    Sep 16, 2013
    Posts:
    334
    Thanks for the heads-up. Does anyone know what namespace "PrefabTypeUtility" lives in? I'm having trouble accessing it.
     
  47. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    638
    You could use SpriteMask to do achieve it :
    https://docs.unity3d.com/Manual/class-SpriteMask.html

    Right now only Sprites are supported by SpriteMask. To achieve this affect your could create a runtime textureless sprite from the Fill area and use it.

    @sharksharkshark It should update Spriteshape whenever points are added/removed or modified. Could you please report a bug with the repro project ?

    AFAIK this is only available in a preview build. (2018.2.0.x - Prefab preview) right now.
     
  48. ChrisIceBox

    ChrisIceBox

    Joined:
    Sep 16, 2013
    Posts:
    334
    I think so too - but that's what I'm using. I'm getting the same API warning as @Jiraiyah, but can't find how to correct it.
     
  49. sharksharkshark

    sharksharkshark

    Joined:
    Apr 27, 2015
    Posts:
    13
    I reported the bug and attached a repro project, but I wanted to add that this seems to affect all build platforms for me.

    I tested with a Windows executable and WebGL and neither of them seem to update my spline points at runtime, even though it works during Play mode in the Editor.

    Has anyone else encountered this?
     
  50. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    638
    Thanks for the bug report. Will take a look asap. As a workaround, you could explicitly call SpriteShapeController BakeMesh() function after making changes to the Spline. Ensure you call it once per frame for each SpriteShape being modified.
     
Thread Status:
Not open for further replies.