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. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    190
    SpriteShapePreview.gif
    We’re happy to share that SpriteShape is now available for preview. SpriteShape is a sprite layout or world building tool that provides the ability to tile sprites along the path of a shape based on given angle ranges. Additionally the shape can be filled with a tiling texture.

    The main feature of the SpriteShape is the powerful combination of a bezier spline path with the ability to tile Sprites adaptively or continuously while automatically switching Sprites assigned to given angles.

    Getting Started:
    1. Download and install the latest Unity 2018.1 beta, here: https://unity3d.com/unity/beta-download
    2. Get a project that includes samples and documentation here: https://github.com/Unity-Technologies/2d-spriteshape-samples
    Take a look at the manuals and try out the samples. We’d like to know what you think, so please reply to this post or create a new one to tell us about your experience with this feature.

    Tell us how this fits into your workflow or enhances your project? What worked smoothly? And what didn’t?

    We’re eagerly waiting to hear back from you!
     
  2. vProject

    vProject

    Joined:
    Sep 11, 2013
    Posts:
    8
    I have been waiting for this for a long time, glad its finally here. I have been using it for a few hours now and have some feedback and questions.

    1. The RGBA values are linked to the wrong channels from the inspector. The R is adjusting the A, the G is adjusting the B, and vice versa.
    2. When I set sprite to medium or low, the corresponding medium / low collider doesn't match it.
    3. You should be able to manually overide selected angles.

    I am using latest Git release of the plugin as 18:00 GMT - 21.3.2018, and Unity 2018.1b11.
     
    Last edited: Mar 21, 2018
  3. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    633
    Thanks for the feedback. This has already been fixed and will be available in next beta (2018.1 b12).

    Collision and Rendering mesh are generated using different tessellation algorithms. Hence there maybe slight differences in generated geometry at low/medium levels. Please file a bug if required.

    To modify angles, you could edit them directly in Inspector for each Angle Range.
    You can also specify multiple sprites for an angle-range. You may then modify SpriteIndex property to select a specific sprite for control-point
     
    Last edited: Mar 21, 2018
  4. tealm

    tealm

    Joined:
    Feb 4, 2014
    Posts:
    108
    Looks great! Any chances of extending the bezier spline deformation so it could be used for animating/deforming 2d characters aswell?

    Rayman legends uses a bezier patch deformation technique for their character animation/rigs. You get that nice deformation instantly for free without the need to manually paint skin weights in a 3d software:

     
  5. vProject

    vProject

    Joined:
    Sep 11, 2013
    Posts:
    8
    I am getting a crash when I roll a ball (circle collider) over a SpriteShape. I have included a screepcap below to show exactly what the SpriteShape collider looks like.

    When rolling the ball along there, sometimes it crashes in seconds, sometimes it takes 5 minutes, but it will always crash. Built to Windows.



    The Output Stack:

    0x000002549E3F85AC (Mono JIT Code) (wrapper managed-to-native) UnityEngine.Collision2D:FreeContacts (intptr)
    0x000002549E3F84E0 (Mono JIT Code) UnityEngine.Collision2D:Finalize ()
    0x000002549E30A649 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_virtual_void__this__ (object,intptr,intptr,intptr)
    0x00007FFA54F78535 (mono) mono_gc_is_finalizer_thread
    0x00007FFA5509CF66 (mono) mono_unity_class_get
    0x00007FFA54F78865 (mono) mono_gc_is_finalizer_thread
    0x00007FFA54FE40C3 (mono) mono_thread_interruption_request_flag
    0x00007FFA5509A05F (mono) mono_unity_class_get
    0x00007FFA7B4D1FE4 (KERNEL32) BaseThreadInitThunk
    0x00007FFA7DF1EF91 (ntdll) RtlUserThreadStart


    No files generated in the crash folder.
    There are no errors in the editer, I tried performing the same actions in the same place, no problems at all.

    Unity 2018.1b12
     
    Last edited: Mar 22, 2018
  6. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    633
    Looks like it could be related to recent Physics2D changes. We will take a look. Please file a FogBugz with a simple reproducible scene if possible.
     
  7. lilisabrina

    lilisabrina

    Joined:
    Feb 28, 2016
    Posts:
    1
    When I click on Edit Spline no control points show up, and also the option to change the point mode is grayed out. Any suggestions?



    edit: I found a solution. Resetting my workspace to Default fixed the problem for some reason.
     
    Last edited: Mar 24, 2018
    foolmoron likes this.
  8. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,964
    thankyou, been waiting for this a long long time :)
     
    oliversitan and zero_null like this.
  9. dawickedeye

    dawickedeye

    Joined:
    Nov 26, 2017
    Posts:
    7
    I'm not sure how to explain this, but I noticed that if I create a new sprite shape profile and add a sprite on top but not on bottom, any created shape will disappear when the camera moves down

    Also, I honestly think the offset slide should be for the sprites not the fill texture.
    Sometimes the user may want the collider to go over the sprites he set up. Specially for ground surfaces and the collider offset will just not be efficient if your shape isn't a flat surface

    Here are some screenshots:

    https://imgur.com/a/cbMmT

    Other than that, great job! Been waiting for this for a while now!
     

    Attached Files:

    Last edited: Mar 26, 2018
    zero_null likes this.
  10. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    633
    I think there could be a bug with BoundingBox generation. Could you please submit a bug with a sample scene/project ? We will try to fix at the earliest.

    We will take a look at this. Thanks for the feedback.
     
  11. Recalc

    Recalc

    Joined:
    Jun 25, 2013
    Posts:
    14
    Hello!

    I am playing around with SpriteShape, but was wondering how I could go about accessing/modifying different points on the Spline via script? I tried looking at the Scripting API, but my tinkering so far has led to no results. I would appreciate any tips that could point me in the right direction!
     
    AndrewKaninchen likes this.
  12. AndrewKaninchen

    AndrewKaninchen

    Joined:
    Oct 30, 2016
    Posts:
    149
    3 questions:
    1. Is the spline editor used in this tool available as a separate component / is it possible to create my own without having to actually reeimplement in some major way? I'd love to use it as a general tool. It could even be used to implement "meta-friezes", as UbiArt calls them (which are basically multiple friezes (smartsprites) driven by a single spline).
    2. Is there a keyboard shortcut/global setting to toggle Edit Spline? First thing I noticed was how much it bothers me to have to click my way out of the scene view to enable it.
    3. Is it possible to move multiple selected points at once? I feel like I've already done it, but now it doesn't seem to work and I'm thinking it might be a bug. Edges between selected points are not highlighting either, if they've ever done that.
    Also, some suggestions on improving the workflow
    • Shift+clicking to a add new point on cursor position. Ferr2D does it and it seems to make quite a lot of sense, although I have not used it yet. That is to say, I know it is possible and not being able to do it makes me uncomfortable.
    • Shortcuts to change point modes (if possible, one that pops up a context menu in cursor position with all point related settings)
    • Esc my way out of Edit Spline to allow selection of another object. The only way I've found how to do this currently is switching tools, which is not really that bad, but because I like the Rect Tool better to work in 2D I find it quite annoying to use since it is bound to T. I'd very much like it better if I could just Esc back to my last selected tool.
    I'll probably come up with some more questions / suggestions as I test it, but so far, I like very much what I've seen. Please, keep it up!
     
    Last edited: Mar 28, 2018
  13. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    633
    You can access the controlpoints data through SpriteShapeController's spline member. A simple sample to animate points below :

    ...

    void Update ()
    {
    var spriteShapeController = GetComponent<SpriteShapeController>();
    var spline = spriteShapeController.spline;
    for (int i = 0; i < spline.GetPointCount(); ++i)
    {
    Vector3 pos = spline.GetPosition(i);
    pos.x = pos.x + (Random.Range(-0.01f, 0.01f));
    pos.y = pos.y + (Random.Range(-0.01f, 0.01f));
    spline.SetPosition(i, pos);
    }
    }

    ...

    Also the source of SpriteShape package is usually located here :
    C:\ProgramData\Unity\cache\packages\staging-packages.unity.com\com.unity.2d.spriteshape@1.0.9-experimental
     
    Recalc likes this.
  14. Recalc

    Recalc

    Joined:
    Jun 25, 2013
    Posts:
    14
    Thank you so much! Can't wait to play around with it!
     
  15. Recalc

    Recalc

    Joined:
    Jun 25, 2013
    Posts:
    14
    So I can't seem to find SpriteShapeController - it says it is missing an assembly file or something.


    This is my manifest.json
    Code (Boo):
    1. {
    2.   "dependencies": {
    3.   "com.unity.2d.common":"1.0.8-experimental",
    4.   "com.unity.2d.spriteshape":"1.0.9-experimental"
    5.   },
    6.   "registry": "https://staging-packages.unity.com"
    7. }

    And in my C# script I am
    Code (CSharp):
    1. using Unity.Experimental.U2D //whatever it's called
     
    Last edited: Mar 28, 2018
  16. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    633
    Yes, it is possible. Also each Angle Range can take upto 8 sprites and its possible to toggle between these sprites at a control point. See the gif attached.

    Will take a look. Also shortcut key for Toggle Point Mode is 'M' and to toggle Sprite Index is 'N'

    Please select all the points and use Shift+Drag.

    Thanks for the feedback.

    As stated above, please use Shortcut key M.

    Will take a look and see how this changes workflow. spriteshape1.gif
     
  17. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    633
    I believe we have found the bug and fixed it. Could you please post a bug with a reproducible scene/project which would help us verify ?
     
  18. dawickedeye

    dawickedeye

    Joined:
    Nov 26, 2017
    Posts:
    7
    Good news!
    Just submitted it
    ID: 1019411
     
    Last edited: Mar 28, 2018
  19. AndrewKaninchen

    AndrewKaninchen

    Joined:
    Oct 30, 2016
    Posts:
    149
    Yes, I know about those. What I meant about the meta-friezes thing was something like this:



    Multiple SpriteShape equivalents being driven by the same curve.

    Oh. Funny, I though I'd tried bashing through the entire keyboard. Well, I was very sleepy by that time. Thanks!


    Wow, that sounds very counter-intuitive for me. Is there a UX/Technical reason as to why it's necessary to hold Shift while doing it instead of just having the points selected and dragging one?

    Thanks for the attention!
    Also, I'm sorry if I've been sounding too bratty about this. It's just that this is a tool of major importance for me, so I'm very much worried about it being consolidated in a less than perfect manner. It's already very good, but it could easily be better and I'm sure other people might have some nice ideas about it as well.
     
    awesomedata likes this.
  20. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    633
    Ah, I see. Thanks for the suggestion. We will investigate adding this in a native way. However you can already add such functionality using custom scripting that mirrors the Spline for the second object. Please find a sample script just for demonstration attached.

    Video for the same:


    We are definitely looking for ways to improve and add features that makes using SpriteShape easier. Please feel free to post your suggestions/ideas/comments :)
     

    Attached Files:

    MechEthan likes this.
  21. dawickedeye

    dawickedeye

    Joined:
    Nov 26, 2017
    Posts:
    7
    I can't believe I missed that the sprites are place on the spline based on their pivot haha
     
  22. Recalc

    Recalc

    Joined:
    Jun 25, 2013
    Posts:
    14
    Hi Venkify,

    I was just wondering if you saw my post regarding the inability to reference the SpriteShapeController. I have the correct Manifest.JSON and using headers.
     
  23. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    633
    Please use UnityEngine.U2D namespace for SpriteShapeController. You may also want to refer to the sample script above.

    Thanks for submitting. We have verified that it has been fixed.
     
  24. Recalc

    Recalc

    Joined:
    Jun 25, 2013
    Posts:
    14
    Okay, thank you
     
  25. AndrewKaninchen

    AndrewKaninchen

    Joined:
    Oct 30, 2016
    Posts:
    149
    Yes, that's very much what I meant. What I thought of in terms of implementation was having a Spline Component in the main GameObject, the children each having one of the SpriteMeshes. In the parent object I would put my MetaSpriteMesh thing, which would reference a base Spline (in this case the one in the same object) as well as a list of tuples of all affected SpriteMeshes and their individual Vector3 (or even full-on Transform) offsets. Using the imported sprite's pivot to avoid the need of manual offset is cool though, haven't though of that. For some cases it surely would be handy.

    Thanks! I'll surely be following the development of the tool.
     
  26. Gamingbir

    Gamingbir

    Joined:
    Apr 1, 2014
    Posts:
    194
    Is this going to be available to use in unity 2018.1?
     
    zero_null likes this.
  27. zero_null

    zero_null

    Joined:
    Mar 11, 2014
    Posts:
    159
    same question
     
    MadeFromPolygons likes this.
  28. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,964
    same
     
  29. ScottyB

    ScottyB

    Joined:
    Apr 4, 2011
    Posts:
    146
    It's available right now to use with the public 2018.1 beta so it's almost definitely going to be available to use in the full release of Unity 2018.1.

    Whether it's going to lose its "experimental" tag before the full release of Unity 2018.1 is unknown but I would lean towards assuming not. But it's available now for testing so if you want to use it, you can.
     
  30. Recalc

    Recalc

    Joined:
    Jun 25, 2013
    Posts:
    14
    How do I set spline detail from the code? This is what I currently have

    Code (CSharp):
    1.  //Add the sprite shape components needed to make the generation
    2.         SpriteShapeRenderer ssR = newTree.AddComponent<SpriteShapeRenderer>();
    3.         SpriteShapeController ssC = newTree.AddComponent<SpriteShapeController>();
    4.  
    5.         //Make a reference to the spline
    6.         Spline mySpline = ssC.spline;
    7.  
    8.         //TODO : Set the spline detail so it can render stuff
    9.        ------- stuck here ----
    10.  
    11.         for (int i = 0; I < points.Count-1; i++){
    12.  
    13.             //Set up our spline points
    14.             mySpline.InsertPointAt(i, points[i] );
    15. }
    16.            
     
  31. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    633
    Do you mean m_SplineDetail member in SpriteShapeController ?
     
    Recalc likes this.
  32. antiart

    antiart

    Joined:
    Dec 6, 2015
    Posts:
    2
    My first thought: This feature demands native support for Vectors/Splines/.svg ! :D

    I just returned from some years Unity absence and this is a nice surprise. Exactly what we need.
    So far no bugs for me.

    Transparency in fill & border produces visible overlay problems (obviously), when the fill has +Offset. 0 Offset on Fill + Bottom Pivot on the Border on the other hand leads sometimes to little gaps. But I guess this can be minimized with carefull sprite planning. I just pushed the Endless/Purple assets around and it seems to be more glitchy the thicker the border is.

    shape_gap.PNG shape_opac.PNG
     
  33. Recalc

    Recalc

    Joined:
    Jun 25, 2013
    Posts:
    14
    Sorry for the plethora of issues,


    but "ArgumentException: shapeParams.splineDetail (0) must be within 4 - 32." comes up, and I cannot figure out how to use the struct.
     
  34. antiart

    antiart

    Joined:
    Dec 6, 2015
    Posts:
    2
    A minor usability request:

    When editing a Sprite Shape Controller, the Sprite Index Slider goes from 0 to 63, regardless of how many Sprites are defined in the Sprite Shape list. Would be nice if that slider would max to the actual number of items in that list. (But this probably may be not so trivial to implement, since every range can have a different number of sprites in it's list...)

    Related: Also nice to have would be a "Random Sprite Index" checkbox in the controller. This is probably easy to script, I did'nt try it yet. But, of course, it would be cooler to have this without additional user code.
     
    teledactyl likes this.
  35. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    633
    splineDetail basically defines subdivision level of the base spline. Acceptable values are between 4 and 32. If you are trying to do procedural generation, I would suggest the regular workflow of using SpriteShape Asset and SpriteShapeController component which makes the setup part easier. You can always alter/add/delete control points on the runtime to procedurally generate spriteshapes. It would be great if you provide more info on what you would like to do. That would be really helpful to us to respond better and improve the feature as required. Also please feel free to post your questions/feedbacks.

    Thanks for the feedback. Good suggestion (a bit tricky given each range can have different number of sprites). Will try to look adding this.

    Yes, as you had mentioned it could be done through a custom script. Also we will add more custom scripts to the Github samples project based on feedback received in the forum in the coming week. Please keep the feedback coming.
     
  36. Recalc

    Recalc

    Joined:
    Jun 25, 2013
    Posts:
    14
    Okay! I am currently trying to spawn a SpriteShape along a user's mouse input to create, say, a tree
     
  37. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    633
    Attached is a simple script to do this. This could be done by just modifying the Spline on the run-time.
     

    Attached Files:

    MechEthan and Recalc like this.
  38. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    970
    I will try this a little later but first I have a number of questions:
    • Does this support holes in the sprites? This is something I implemented in our internal version of Ferr2D by introducing the concept of subterrains. The subterrains were individual Ferr2D components, allowing full edge editing etc. but they were bound by the parent terrain and would be fed into the parent's triangulator with reverse winding. Very useful for complex layered terrains.
    • Does it support local overriding of the edge graphic at a control point, ignoring the angle?
    • Most importantly, does it come with source?
     
  39. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    633
    Yes, this can be overridden per control-point. (Just add multiple sprites for the Angle-Ranges and set the SpriteIndex for the corresponding point).
    Most of the source is available in the package except the geometry generator which is part of Engine written mostly in native SIMD for high performance.
    Could you please provide more info ? Perhaps screenshots or sample scenes should be helpful.
     
  40. Recalc

    Recalc

    Joined:
    Jun 25, 2013
    Posts:
    14
    Thank you for your help! I appreciate the support you've been giving to us
     
  41. Recalc

    Recalc

    Joined:
    Jun 25, 2013
    Posts:
    14
    Is there a way to modify control points on their z?
     
  42. RaffaLinux

    RaffaLinux

    Joined:
    Jan 10, 2014
    Posts:
    3
    Could you make colliders work better considering also the height of the spline? I'm trying to use the new feature to build a sort of 2d race track but i can't make my collider match both the inner and outer bound of the path.
    Also, there are gaps because of the texture not being applied properly.
     
    Last edited: Apr 18, 2018
  43. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    633
    You can modify the Z position of control-points. However, SpriteShape geometry generation is pure 2D only. And 2D sorting works as usual for SpriteShapeRenderer.

    Thanks for the feedback. I believe you use different height values for each control point. We will take a look into fixing this.

    Could you please post a sample scene or submit a bug report?
     
  44. RaffaLinux

    RaffaLinux

    Joined:
    Jan 10, 2014
    Posts:
    3
    I discovered that it was an error on my side, there were some pixels at the border that were slightly transparent.
    As about the collider i guess that you should add the chance of having different kind of colliders/collider modes.
    Right now i can think of having a polygon collider for the shape, one edge collider for outer border and one for inner border (so we have four modes: polygon collider, inner border, outer border, both borders).
    And obviously it should actually match the different heights of the shape, right now it doesn't.
    I'm using a workaround and setted all my heights to 0.8 but i can't have different height values as you said.
    This way you can use this tool in a way that i guess you didn't thought about before such as 2D race games with a track.
     
    Last edited: Apr 19, 2018
  45. WoelieWoel

    WoelieWoel

    Joined:
    Apr 18, 2018
    Posts:
    3
    Not sure wether this is supposed to be posted here,

    I tried this on 2018.1.0b12, 2017, 2018.1.0.b13 and just now 2018.2.0b1, but I fail to open the SpriteShape on my windows 8.1 There are missing scripts and the samples don't render. As shown in the spoiler:

    unitySpriteShape.png

    The manifest.json that came along seems to be right, just like on github. It has been unzipped. I imported it to the projects assets folder.

    Maybe this is useful
    ProgramData>Unity>cache>npm>packages.unity.com>com.unity.2d.spriteshape>.cache.json gives:
    "{\"error\": \"not_found\", \"reason\": \"document not found\"}"

    Any idea what I am doing wrong? I am really looking forward to use this tool.
     
  46. rustum

    rustum

    Unity Technologies

    Joined:
    Feb 14, 2015
    Posts:
    190
    @WoelieWoel:
    Thank you for this report! Could we get a screenshot that shows your fully expanded project view as well? This will help us understand what files are missing.
     
  47. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    633
    Nice. For procedural generation, an alternate way is to make use of Bevel Cutoff and Bevel Size options. This simplifies and generates smoother SpriteShape without the need to specify Tangents. These options can be specified per SpriteShape asset or per control point.
     

    Attached Files:

  48. WoelieWoel

    WoelieWoel

    Joined:
    Apr 18, 2018
    Posts:
    3
    Ofcourse, Rustum :)

    ProjectView.png
     
    Last edited: Apr 19, 2018
  49. RaffaLinux

    RaffaLinux

    Joined:
    Jan 10, 2014
    Posts:
    3
    @Venkify Yes that's exactly what i'm trying to work on thank you for the advice :D. Could you please do something about the height issue and the modes for the collider? In my specific case i guess (still have to try) that i could achieve what i'm trying to build by setting the collider at minimum offset, copy the collider and then change the offset to its maximum value by code, but of course i would really appreciate having an option for that . But still, i can't to that with the height issue that i mentioned before...

    EDIT: i've tried using the bevel cutoff as you suggested and i have got even more problems with the collider unluckly:(. I still need to activate the tangents to get the collider follow my curve. With the straight line point to point mode, the collider actually follows the straight lines without following the rounded bevels. I guess that the issue is that the collider, as it is now, will always be based on the setted curve and not on the actual shape that the sprite has, which works nicely in a lot of situations but it is a big limitation in a lot of other scenarios.
     
    Last edited: Apr 19, 2018
  50. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    633
    Thanks again for the feedback. We will try to fix this in an upcoming version. Will post an update later on this.

    The file manifest.json which defines the packages to be loaded must reside outside the Assets folder within the Root folder of the project.

    Project -
    - Assets
    - Documentation
    - Packages (manifest.json resides here).
    - ProjectSettings
    - Library
    It looks like you downloaded the zip from Github and unzipped directly within the Assets folder. Please try moving Packages folder to the Project Root. This hopefully should fix the issue.
     
Thread Status:
Not open for further replies.