Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

SpriteShape Preview Package

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

  1. sharksharkshark

    sharksharkshark

    Joined:
    Apr 27, 2015
    Posts:
    13
    Interesting!

    When I add a BakeMesh() call after all of my point updates, I receive this error when running in the Editor:

    Code (csharp):
    1. ArgumentException: shapeParams.splineDetail (0) must be within 4 - 32.
    2. UnityEngine.Experimental.U2D.SpriteShapeUtility.GenerateSpriteShape (UnityEngine.Experimental.U2D.SpriteShapeRenderer renderer, SpriteShapeParameters shapeParams, UnityEngine.Experimental.U2D.ShapeControlPoint[] points, UnityEngine.Experimental.U2D.SpriteShapeMetaData[] metaData, UnityEngine.Experimental.U2D.AngleRangeInfo[] angleRange, UnityEngine.Sprite[] sprites, UnityEngine.Sprite[] corners)
    3. UnityEngine.U2D.SpriteShapeController.BakeMesh (Boolean needUpdateSpriteArrays) (at C:/Users/nolen/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.2d.spriteshape@1.0.12-preview/Runtime/SpriteShapeController.cs:292)
    4. UnityEngine.U2D.SpriteShapeController.BakeMesh () (at C:/Users/nolen/AppData/Local/Unity/cache/packages/packages.unity.com/com.unity.2d.spriteshape@1.0.12-preview/Runtime/SpriteShapeController.cs:246)
    and then I see the same behavior exhibited during a build! My mesh has stopped updating its points visually, even though the game continues to run.

    My SpriteShapeController has had its Spline Detail set from Low through High Quality, with the error occurring regardless of value, and I've even attempted to set the value of the integer in my script as well.


    I'm curious if this could relate or possibly explain the build issues I'm seeing?
     
    Last edited: Jul 17, 2018
  2. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    102
    @sharksharkshark As long splineDetail is 4 - 32 it should generate fine. And it does seem you have not modified it through scripting. Lets take a look at this bug. Could you please post a sample repro scene/project ?
     
  3. sharksharkshark

    sharksharkshark

    Joined:
    Apr 27, 2015
    Posts:
    13
    I've actually already added a sample project when I submitted my bug report. I believe the Case/Inquiry Id is 1060558, if that helps track it down :).
     
  4. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    655
    This is really great so far! -- I really like the interface of assigning sprites!

    Only a few small improvements I see are necessary for better usability:

    1. Being able to select a sprite slice (instead of just a texture) for a fill by default (such as a tile fill from a tileset), if for no other reason than consistency (and convenience) in producing graphical assets for this system.

    2. Allowing us to change the fill size/scale more easily (and separately from the edges -- I sometimes need a different PPU for the fill than I do for the edges)

    3. Selecting multiple angles at once to apply the same sprite to (by holding the ctrl or shift key) rather than selecting them individually.

    4. A togglebox to enable/disable "automatic" on all corners of a spriteshape at the same time. (If the mesh-generation can figure out where corners are based on the spline, surely it can pass that along to the spline itself to know which point generated the corners and set them to generate corners automatically when a button/toggle switch is pressed.)

    Outside of those things, this is a really great tool! -- I would really like to use it more easily though, so please consider adding the things I mentioned above, guys!
     
    Last edited: Jul 19, 2018
  5. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    655
  6. Venkify

    Venkify

    Unity Technologies

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

    Fill part of the SpriteShape requires the Texture Wrap Mode to Repeat so UV generation is simplified and tessellation therefore is fast and simple. This can be problematic if Sprites are used especially if its a part of SpriteSheet or Atlas.
    The idea is to ensure SpriteShape is as fast as it can be so it can modifiable at runtime.

    This property is already available under Fill -> Pixel Per Unit in the SpriteShape Profile Inspector.

    Thanks for the suggestions. We will consider adding these in the upcoming release.

    Please post the sample project for Issue 4.


    Thanks for submitting the project. We managed to reproduce it and will fix it asap.
     
    Last edited: Jul 20, 2018
  7. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    655
    That makes sense -- but wouldn't it be possible to grab the spriteslice and generate a texture from it? For example, add a button in the spriteshape profile inspector to generate a texture (based on the chosen slice) and attach it automatically to the spriteshape profile with the proper settings (for example, set the repeat mode to "clamp" while you're at it, because I didn't even know this was even a requirement.)


    Ah, I see it now! -- I'm not blind, but I also clearly wasn't aware this control was supposed to be "grouped" with the "Fill" (despite it being bolded) because I assumed "fill" could either be referring to the next line (the texture input), and PPU would be for the edges for the entire sprite shape (since that made the most sense to me because there doesn't seem to be any way to change that for them, and PPU does seem to affect the edges, in addition to the fill, and which I would have expected there to be a way to set them each separately).

    Regarding the UI confusion -- I would have expected more of a "heading" font style to visually-separate large groups of controls (i.e. a larger font) because the "Angle Ranges" UI overpowers all the rest of the control groups, mainly due to its (extremely-heavy!) visual-weight! It's not a bad idea to have this section so large (because it is a great feature!), but please put it either at the top or at the bottom of the UI (to make it interfere less with the rest of the control "groups" to make them more intuitive.) This is especially important if you're going to keep the normal-sized labels and are still going to simply bold them to indicate the "grouping" of the controls because it was the grouping itself (based on the behavior I saw) that confused me...


    Done! -- You'll find it in the (updated) issue!


    I've got two final suggestions to cover all possible use-cases:

    1. Is it possible to add an option to simply "overlay" a static decoration at the corners (automatically) rather than stretching/integrating them into the mesh? (For example, if I were to create a "joint" at the corners that was a circle, it would stretch the circle "joint" and make it look terrible.)
    2. This is just a curiosity of mine -- how would you suggest to do parallaxing "layers" with these? For example, what if I wanted to use sprite shapes on different 2d orthogonal "planes" and simulate perspective with them by creating parallax -- this would be like how Ferr2D does for simulating parallax effects using the spriteshapes as parallaxing terrains based on their zdepth (in the most performant way possible?) -- Is this a feature you guys might consider adding to the spriteshape? -- I'm pretty certain most people will use it this way, in general, as well.

    Other than what I've mentioned so far, this is a excellent tool -- and works pretty well for preview!


    (Also -- I forgot to mention! -- there's an error when moving spline points too close together -- you should probably combine them if they're too close, or don't update the mesh until they're farther apart!)
     
    Last edited: Jul 20, 2018
  8. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    655
    https://github.com/Unity-Technologies/2d-spriteshape-samples/issues/5

    I've added another issue I just noticed there was no workaround for -- I was pretty certain it would have been taken care of by now, but I'm going to post it anyway just to inform you guys in case you didn't know about it.

    Basically, this:



    versus this:



    Having BOTH behaviors for corners would be ideal -- just add an "overlay" option to the corners on the spline point. It would use the same corner sprite slice (just in a different way, as described above.)



    Also, as an alternative to the "stretch" behavior, it wouldn't be a bad idea to be able to offset those "overlay" corners either (i.e. shift across the spline's local orientation -- for example, if I wanted to shift it to the inside for the left "corner" and closer to the outside for the right "corner").

    Here's an example:



    Although this involves submeshes, perhaps it can still be done in a single drawcall? -- I'm assuming you've already got a way to deal with that with the edges.
     
    Last edited: Jul 20, 2018
  9. CodeFighter

    CodeFighter

    Joined:
    Dec 15, 2012
    Posts:
    62
    I use Unity 2018.2.0f1
    I have downloaded the project from Github
    And I have this.
    The type or namespace name 'SpriteShapeController' could not be found (are you missing a using directive or an assembly reference?) [Assembly-CSharp]

    It looks like this project doesn't include SpriteShapeController.
    Where can I get it?
     
  10. PGJ

    PGJ

    Joined:
    Jan 21, 2014
    Posts:
    870
    Add it from the Package Manager in the Unity Editor (you'll find it under the Window menu).
     
    CodeFighter likes this.
  11. CodeFighter

    CodeFighter

    Joined:
    Dec 15, 2012
    Posts:
    62
    Thank you!

    I use SpriteShape to create free shape objects using only texture.
    I need to create SpriteMask of borders of this object, so I need to create a sprite with the same shape like my SpriteShape object
    Is there any way to get the sprite from SpriteShapeController?
    or could you suggest what particular values I can use like vertexes to create textureless sprite
    or any another way? What is Fill area you suggested?
    Thank you very much!
     
  12. CodeFighter

    CodeFighter

    Joined:
    Dec 15, 2012
    Posts:
    62
    Nevermind I solved it with rendering to a texture.
     
  13. CodeFighter

    CodeFighter

    Joined:
    Dec 15, 2012
    Posts:
    62
    Could you tell me is there any way to delete a point in edit mode?
    Thank you
     
    Last edited: Aug 1, 2018
  14. rushk1

    rushk1

    Joined:
    Sep 24, 2017
    Posts:
    24
    Sorry if I misunderstood the question but i think this is what you need Select the point and press the delete key
     
    CodeFighter likes this.
  15. CodeFighter

    CodeFighter

    Joined:
    Dec 15, 2012
    Posts:
    62
    This is exactly what I need, thank you very much!
     
    rushk1 likes this.
  16. CodeFighter

    CodeFighter

    Joined:
    Dec 15, 2012
    Posts:
    62
    It looks like the SpriteShape has a limitation in particular point amount. Isn't it?
    After some points, it stopped to render a texture.
    IMG_02082018_193022_0.png
     
  17. dquek

    dquek

    Unity Technologies

    Joined:
    Apr 17, 2018
    Posts:
    12
    Hi there, QA here! :)

    We are trying to reproduce your issue with no success so far.
    For the mentioned issue, point amount should not be the case, there is no point limit.

    Do you see the texture when in Play mode?
    Could you share your Texture Import Settings and SpriteShapeProfile Settings?

    It would be great if you are able to file a bug report with a sample repro project through = Unity > Help > Report a Bug...
    or
    Let me know any more info you can provide here and I'll investigate it.
     
    Last edited: Aug 3, 2018
  18. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    655
    It looks like your points are really close together on the "point" of the errant triangle -- Spriteshape doesn't like that AT ALL (at least as of 2018.2.0f2), so it pops out some warnings and does weird things when rendering.

    You're probably running into that issue. Try moving them away from one another (or deleting a few and using the "curve" option for that section of those points) to make it go away.

    I think it's trying to draw the triangle to the "nearest" point it can in a straight line, but in your case, you have a really long surface area with no points on it, so it can't figure out which point to draw it to except for the most recent point it was able to (then it gets confused). It may be a "bug" or a "feature" (depending on who you ask), but it's probably just expecting the points to be a lot more distant instead of right on top of one another.
     
  19. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    655

    I've reproduced this by changing some corners to adaptive and some with adaptive UVs disabled (with slopes of particular angles), so I think my previous suggestion to @CodeFighter might have been a bit too soon.

    SpriteshapePixelsLost.png

    SpriteshapePixelsLost1.png
    SpriteshapePixelsLost2.png


    It's definitely an issue -- but only at particular angles -- if I move the selected point slightly upward or downward, the edge reappears:

    SpriteshapePixelsLost3.png

    Moving on X (on this particular point) doesn't seem to matter, but when I move it on Y+ or Y- it reappears. It seems to depend on the angle of the line itself.

    An additional problem:

    There seems to be a 1px extra on the UV display too which, at certain angles (with various adaptive settings for various corners and angles), break on lower-resolution sprite shapes (such as the few textures I've submitted to the "Issues" section on github.) These are 100ppi textures and 100ppi sprites, so I would think 100ppi would work as a good "percentage" to indicate how much of a UV to keep and how much to toss?)
     
    Last edited: Aug 6, 2018
  20. CodeFighter

    CodeFighter

    Joined:
    Dec 15, 2012
    Posts:
    62
    Looks like it was "Control points 3 & 4 are too close to each other. SpriteShape will not be generated."


    Thank you
     
    Last edited: Aug 5, 2018
    awesomedata likes this.
  21. awesomedata

    awesomedata

    Joined:
    Oct 8, 2014
    Posts:
    655


    This is a clearer explanation of what is happening with the edges above "popping" into and out of existence at certain angles.

    Additionally, this also shows the 1px "distortion" on the displayed edge sprite that I was referring to when different (nearby) points vary on their being "adaptive UV" set to true or false.

    I feel the two issues may be related.
     
  22. CodeFighter

    CodeFighter

    Joined:
    Dec 15, 2012
    Posts:
    62
    Can I use this package for my project in the Asset Store?
    I'm asking because it is still in Preview status but it works fine for me.
     
  23. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    102
    Yes, please do. Also please feel free to post feedback, bugs or suggestions here.

    @awesomedata
    Thanks for the feedback again. Some of the issues have already been fixed and we will publish a new version soon.
     
  24. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    510
    Feature Request:

    I would love to be able to apply a different physics material based on the angles set up in the SpriteShapeProfile.

    Imagine I'm making a snowy mountain side. Lower angles would be snow covered while steeper angle would be bare rock. I'd like the snowy areas to be more slippery and the rocky areas more sticky. I'd need to apply different physics materials to do this.

    Is this something you are planning? Or is this something you could potentially add? I think Ferr2D allows it although I have not confirmed that.

    -Jeff
     
  25. DanielThomas

    DanielThomas

    Joined:
    Mar 30, 2013
    Posts:
    58
    I have a problem, see attachment.

    When I load the project the spriteshapes looks as intended, but after I run it the first time I get the glitch problems shown at the bottom of attachment. I'm not sure how to solve this or what it can be caused by.
    - Creating new sprite shape using an existing profile gives same glitch.
    - Creating new SpriteShape profile gives the same glitch.

    I use Unity 2018.2.2f1 and latest SpriteShape Preview 1.0.12.

    I can't pinpoint when it started but it worked and after I added some more spriteshapes, next time I ran the play I got these errors.
     

    Attached Files:

  26. rushk1

    rushk1

    Joined:
    Sep 24, 2017
    Posts:
    24
    For generating a SpriteShape based on a Vector3 Array of points, should I be using Spline.InsertPointAt or SpriteShapeUtility.GenerateSpriteShape ? I have a list of points that I generate from a source image based on its sprite outline, but if the shape is more complex Spline.InsertPointAt will need more work on sorting the points correctly. I'm hoping that given an array of Sprite Vertices it will be easier to generate a spriteshape using SpriteShapeUtility.GenerateSpriteShape but can someone give an example of using SpriteShapeUtility.GenerateSpriteShape..

    Code (CSharp):
    1.  sourceSpriteRenderer = GetComponent<SpriteRenderer>();                                                  
    2. sourceSprite = sourceSpriteRenderer.sprite;
    3. Vector2[] sourceVertices = sourceSprite.vertices;
    4. Vector3[] sortedSourceVertices = ConverttoVector3(sourceVertices);
    5.  
    6.  
    7.  
    8. Vector3[] ConverttoVector3(Vector2[] SourceVector2)
    9.     {
    10.         Vector3[] resultingVector3 = new Vector3[SourceVector2.Length];
    11.         for (int i = 0; i < SourceVector2.Length; i++)
    12.         {
    13.             Vector2 tempV2 = SourceVector2[i];
    14.             resultingVector3[i] = new Vector3(tempV2.x, tempV2.y, 0f);
    15.         }
    16.         return resultingVector3;
    17.  
    18.  
    19.     }
    20.  
     
  27. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    102
    We will explore the possibility of adding such feature. Will update soon.

    Please check
    1) If the Sprite is imported as Tight Mesh type.
    2) If the Sprite are part of Atlas and its enabled in Editor check
    1) Tight Packing
    2) Rotation.
    Both could cause artifacts.
    3) If possible please file a simplified repro project. Will take a look asap.

    I understand that you are trying to use a Sprite's geometry data to construct Sprite-Shape. Could you please be more specific about your use-case and how you plan to use it ? That would help us more.
     
  28. DanielThomas

    DanielThomas

    Joined:
    Mar 30, 2013
    Posts:
    58
    That did it, thanks!
     
  29. jeffweber

    jeffweber

    Joined:
    Dec 17, 2009
    Posts:
    510
    What would be the best way to modify the fill color dynamically at runtime. I know I could probably swap out fill textures but I want to change the color continuously as things happen in my game. Is this possible?
     
  30. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    102
    You could potentially use SpriteShapeRenderer Color parameter ? Or could you please be more specific to what is needed ?
     

    Attached Files:

    jeffweber likes this.
  31. foolmoron

    foolmoron

    Joined:
    Jun 22, 2013
    Posts:
    30
    When I use 2018.2.3f1 with SpriteShape Preview 1.0.12, I can create a new SpriteShapeController in the scene which has a square shape, but when I try to Edit Spline, no controls or anything show up in the editor. Any ideas?
     
  32. foolmoron

    foolmoron

    Joined:
    Jun 22, 2013
    Posts:
    30
    Well I tried the sample project with 2018.1.0b12 and 2018.1.9f1 and there's still no controls for editing splines
     
  33. foolmoron

    foolmoron

    Joined:
    Jun 22, 2013
    Posts:
    30
    Oh huh resetting to Default does work. That is weirdly aggravating. I need my layout D:

    But then I recreated my old layout and it stopped working...

    Okay, the problem specifically is with multiple Inspector tabs. When you click Edit Spline and both inspectors are looking at the a SpriteShape (even different objects), then the controls don't show. If you lock the other inspector to a non-SpriteShape object so that only one inspector is looking at a SpriteShape then it also works fine.

    I guess no one at Unity uses the multiple-locked-inspector-tabs trick :p Is this bug logged somewhere?
     
    Willkuerlich likes this.
  34. SimonOliver

    SimonOliver

    Joined:
    Jul 16, 2007
    Posts:
    21
    Hi,

    We're taking a look at SpriteShape at the moment, and it looks really nice. There are a few issues that we've had though. Not sure if there existing workarounds?

    1. We're using SpriteShape in a 3D scene, and want the "fill" section of the SpriteShape to render to the depth buffer, with the detail/angle sprites rendering afterwards. Right now it only seems possible to specify a material for all sprites (so this is only possible with ZTest always or there is z-fighting). Being able to specify a separate material for the fill and one for the edges would be super useful for this use case, and would support a bunch of other effects where you might want the body to have a different look/feel to the edges.

    2. We're building some sections with code. Right now it seems that the Color property is not exposed so we had to used SerializedProperty to access.

    3. We're creating 3D extrusions from some SpriteShape objects (using a similar method to the Edge collider methods in SpriteShapeController), but as this doesn't match the SpriteShape edge vertex positions exactly, there are a few gaps between the extrusion mesh and the original spriteshape mesh. I'd love to have a way of accessing the definitive edge vertices.

    4. There doesn't seem to be a way to force the bounds to update if creating SpriteShape objects with code (right now we have to zoom far out for a frame to force an update). Having access to bounds or "force bounds update" function would be great.

    Thanks, keep up the great work!
     
  35. SimonOliver

    SimonOliver

    Joined:
    Jul 16, 2007
    Posts:
    21
    I submitted the first as bug #1079942
     
  36. haywirephoenix

    haywirephoenix

    Joined:
    May 17, 2017
    Posts:
    36
    Hey, thanks for the awesome work on this. I keep discovering great features.

    I'm wondering if it's possible for the points to interact with a collider at runtime, eg to bend around
    a circleCollider2D.
    I noticed someone mention ClosestPointOnCurve in BezierUtility but cannot find any usage for this and it returns a vector3 instead of an int. Is that what I need? I can add points but not in the correct position:
    Code (CSharp):
    1. spline.InsertPointAt(spline.GetPointCount(), mousePos);
    2.  
    Do I need to find the index of the closest point in order to add one next to it?

    Thanks!



    How to use this? What is "progress"? I noticed "mod" inside SplineUtility, for now have copied it next to this function in my script.
     
    Last edited: Sep 12, 2018
  37. haywirephoenix

    haywirephoenix

    Joined:
    May 17, 2017
    Posts:
    36
    Update: The transform scale and position are factors with GetPosition. If the scale is not 1,1,1 or the position is not 0,0,0 you will run into issues.


    Code (CSharp):
    1.  
    2. for(int i = 0; i < spline.GetPointCount(); i++){            
    3. Vector3 pos = spriteShapeController.spline.GetPosition(i);
    4. Instantiate(circle, pos, Quaternion.identity);
    Getting the point positions a lot more accurately now, still not perfect, just want to add a point on the bezier curve at the mouse position. At the moment I'm trying Vector3.Project on the point and the mouse to see if the new point needs to be added to i+1 or i-1 in the chain. Any ideas?
     

    Attached Files:

    Last edited: Sep 13, 2018
  38. haywirephoenix

    haywirephoenix

    Joined:
    May 17, 2017
    Posts:
    36


    Code (CSharp):
    1. spline.InsertPointAt(spline.GetPointCount(), mousePos);
    2. var newPointIndex = spline.GetPointCount() - 1;
    3. spline.SetTangentMode(newPointIndex, ShapeTangentMode.Continuous);
    Need help! What's the most efficient way of getting the index on the curve? SplineEditor.cs can do this
     
  39. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    102
    @SimonOliver Thanks for the suggestions and feedback.

    We will take a look into this.

    We will try to add this to scripting in the upcoming versions.

    Would be please provide us a screenshot or video.. That would help us understand the requirements better.

    Got it. We will look into this. However in Editor mode, you could try calling ResetHash() of SpriteShapeController to force generating SpriteShape again. Please let us know if this helps. Thanks again for the feedbacks.

    Please take a look at : BezierUtility.ClosestPointOnCurve function in com.unity.2d.spriteshape\Runtime\BezierUtility.cs
    being used in com.unity.2d.spriteshape\Editor\ShapeEditor.cs LayoutEdges() function which is probably what you need. Please let us know if this helps. Thanks for the feedback.
     
  40. SimonOliver

    SimonOliver

    Joined:
    Jul 16, 2007
    Posts:
    21
    Sure - here is a simple example of what we have at the moment - it's using the same code that SpriteShapeController uses to generate the Edge collider. It creates an extrusion mesh, but as the sampling doesn't use identical spline sample positions as SpriteShapeRenderer does internally, there are small gaps between the surface mesh and extrusion mesh. It would be great to have access to the exact vertex positions from the SpriteShapeRenderer edge to be able to match them exactly. Screen Shot 2018-09-14 at 08.58.28.png
     
  41. SimonOliver

    SimonOliver

    Joined:
    Jul 16, 2007
    Posts:
    21
    This doesn't help, sadly. When we create a new SpriteShape with code the bounds are empty. It looks like the bounds are only updated when the centre point (0,0,0) is within the camera view (which in our case doesn't happen until the whole scene is in view due to lots of large objects). I'm guessing this is called on OnPreRender or something similar where bounds are updated if empty? This obviously won't help if the centre point is off-screen. Is there a private function that I can call via reflection in the meantime? Thanks again.
     
  42. haywirephoenix

    haywirephoenix

    Joined:
    May 17, 2017
    Posts:
    36
    The lengths that I'm going to here and I still dont know how to set the correct int and shuffle the existing points along one. The function you mentioned uses HandleUtility.nearestControl which I cannot use in playmode when checking with the mouse. BezierUtility.ClosestPointOnCurve returns a Vector3 instead of an int. I know that you could probably solve this with one line of code. How do I add a point to a circle without messing it up? Do we need to check if we are closer to the nextindex / previousindex before adding a point? An example would be really helpful.



     
    Last edited: Sep 17, 2018
  43. haywirephoenix

    haywirephoenix

    Joined:
    May 17, 2017
    Posts:
    36
    Where have all the unity Devs gone? Hardly any support for their own packages.
     
  44. Sergi_Valls

    Sergi_Valls

    Unity Technologies

    Joined:
    Dec 2, 2016
    Posts:
    109
    You need to iterate through all the Bezier segments in the spline. In every iteration you calculate the nearest distance. If the distance is less than the previous nearest distance, store that index. This is the "int" you are looking for.
    For splitting, you need to get that Bezier segment and split it using BezierUtility split functions. That will give you the left and right tangents needed to preserve the shape once you add this new point.
     
  45. Time_Flys

    Time_Flys

    Joined:
    Feb 12, 2015
    Posts:
    11
    Been using this for a bit now, and loving it! It's definitely a huge time saver. I had a few questions regarding Sprite Indexes, and Sprite Borders.

    Is there a way to auto-randomize the sprite variant? Having to individually select each node and choose a variant is a major time consumer. Would be nice if it just chose one at will for me, so I don't have to make additional nodes simply for the sake of changing my background trees.

    Also, along the same lines I'd love to see "Flip X/Y" just like a (Sprite Renderer has) options instead of having to bring the same sprite into Unity, but flipped and add it as a variant. Seems unnecessary.

    Now with Sprite Borders. See "Adding_Node" screenshots. Why the heck is this happening? I add a node and it immediately defaults to "Tangents Not Linked" as my point mode option. Which then causes my borders to be added in 3 places. So then I have to select all three nodes and switch their point modes to "Tangents Mirror each others angle" and my borders disappear again. I'd love to either A have a way to select a default option or B not see the borders in the first place.

    What I'm suggesting might already exists, but I haven't found anything of the sort yet. Anyways keep up the great work! I'm excited to see where SpriteShape goes.
     

    Attached Files:

  46. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    102
    @Time_Flys Thanks for the feedback.

    We will add a demo to the Samples package.

    Good suggestion. We will review this and will update this thread.

    We are trying to come up with automatic Point mode setting that takes into account the neighbor points and various scenarios .

    We will soon come up with another major update with all the fixes soon. Will keep this thread posted. Thanks again.
     
    Time_Flys likes this.
  47. Kroc_

    Kroc_

    Joined:
    Jul 23, 2014
    Posts:
    24
    Bugs and Features feedback:

    Multi object edit:
    1. if you select multiple objects with SpriteShapeController and click Edit Spline it does.. uh.. DON'T TRY (well do try if you're dev!). Would be very great to have this actually working for big levels to edit multiple stuff at once and not have to, between each object, move and click 3 times (edit spline end => select new object => edit spline start).

    2. Is/will there be a shortcut for Edit Spline mode or a way to trigger it from a custom Editor script? (because there definitely should be one)

    In Edit Spline:
    3. When selecting multiple points only thing you can do unless im missing something is delete all the points selected. Would be great to be able to move all the points selected at once. Being able to change Point Mode for multi points would also be nice.

    4. Behavior for selecting slightly wrong (this will irritate a lot of people): right-click pans but it also deselects points when it shouldn't, shift+click on an already selected point should deselect it but it doesn't, and click+drag on a point deselects all others and moves it while it should only do that if the point wasn't selected before but if it was it should move all selected points together and not deselect any of them.

    5. Very odd choice of colors for the points, default is white, alright, but.. selected is.. yellow?
    Lemme repeat that: YELLOW??! That's very close to white as you can (CAN'T) see, it is particularly hard to distinguish both selected and unselected on an also light background. RED, MAGENTA or GREEN would be good.

    6. I'd love to be able to make the point nodes bigger to select, like a global slider in the gizmos. The max could be at least 3 times bigger. It is too precise to feel intuitive and good sometimes, I mean especially when you're tweaking a branch 10 times wider than the spline, the nodes only show in Spline Edit anyways it is not like they're gonna clutter. If you want more precision you can also just zoom in as the UI scale stays the same at all zooms.

    *Please also apply the handles color and scaling suggestion to the 2 "pin" nodes (dunno what they're called) that appear when u select 1 point to tweak the curve (in fact maybe the selected point could be green and its 2 pins red to further distinguish both and not being "all in" on one color which you wouldn't see well on a background close to that color).

    ***

    Anyways this is (the start) of a great feature lacking in almost all 2D game engines for making levels ground/walls but also a lot for environment art without being forced to a tilemap or rectangular (9-slice sprite) style or duplicating stuff to simulate a rough path or having to directly draw things like tree branches in drawing software and never being able to play with them or vary them or even texture swap them without having to redraw everything.

    If you combine this with a little Editor script, a graphical tablet Pressure Pen and you would be able to really DRAW/PAINT branches, ground paths, walls, RIVERS.. so many beautiful things.. with sick varrying width.. In Unity.. IN 1 SECOND?!! Very very awesome, I've been waiting for this.
    In an XZ (sidescroller) game you can use that a lot for decorations especially vertical like trees, fancy lamposts..
    In an XY (topdown) game you can use it less so for decorations but great for ground paths, rivers..
    In both cases amazing for very familiar things like terrain and rampant vegetation.
    Again this is so cool because it would allow you to actually just.. have fun in the editor. Having fun making your game, that's gonna be a good game.
    Keep up the good work and thank you!
     
    Last edited: Oct 9, 2018
  48. liven999

    liven999

    Joined:
    Oct 7, 2015
    Posts:
    18
    Hello,

    I have some fun with this new feature but have a question :

    How can I update collider when I modify the shape in real time script.

    It works if I move nodes with the mouse (in real time too), but when I do it by script it don't update the collider.
    The only way I found to update it is to uncheck and check again the "Update collider" in the inspector but it seems we can't modify this variable in script.

    Any idea?
     
  49. artificialLimbs

    artificialLimbs

    Joined:
    Mar 27, 2017
    Posts:
    3
    liven999: "How can I update collider when I modify the shape in real time script."

    Looks like there is a BakeCollider method in the Sprite Shape Controller script that bakes the collider.
    I would think you could do something like

    using UnityEditor;
    using UnityEngine.U2D;
    public SpriteShapeController sc;
    void Update() {
    sc.BakeCollider();
    }

    But imagine this might not be good for performance. I've found the baked colliders to be pretty sketchy, also, and have usually needed manual adjustment.
     
  50. liven999

    liven999

    Joined:
    Oct 7, 2015
    Posts:
    18
    @artificialLimbs thank you very much for your answer.
    It works, but you are right it is heavy and generate GC alloc so I'll be careful