2D Sprite Shape is out of preview for 2019.3

ok next question :smile: How to smoothen ShapeTangentMode.Continuous? When set in code, these draw the same as Linear.

I noticed theres a smoothen function in extras by @Venkify

https://github.com/Unity-Technologies/2d-spriteshape-samples/blob/master/Assets/Unity Technologies/2D SpriteShape/Extras/Scripts/SimpleDraw.cs

However this is for a specific purpose and not suited to a non-open ended shape

1 Like

two more feature ideas…

  1. please make it possible to use the Sprite Shape Renderer as a Sprite Mask or,
  2. please make it possible to have convex sprite shapes. (holes)

I’m running into these two road blocks on a top down game, it’s awkward to use sprite shape as organic shaped walls… it seems to be only designed with platformers in mind… I want the fill on the outside and the path sprites on the inside (as mentioned a few times in this thread, the fix at the top of the page is no good for me as the walls are randomly generated)

Being able to use a Sprite Shape Renderer as a mask would instantly solve this problem as I could just punch a hole in a sprite and use the same shape on another object to draw the profile

1 Like

@Venkify I get an error when trying to dynamically make a shape, sometimes I get this:

ArgumentException: Internal error: Point too close to neighbor
UnityEngine.U2D.Spline.InsertPointAt (System.Int32 index, UnityEngine.Vector3 point) (at Library/PackageCache/com.unity.2d.spriteshape@3.0.15/Runtime/Spline.cs:60)

This would be a major problem in a game, as it crashes the playloop. Instead of crashing because points are too close, could they just be skipped or merged instead?

I can check my points that I am feeding it, however how close is “too close”?

So I figured out a pipeline for doing inverse sections, it’s not an extension for Sprite Shape but rather a work around:

  • fill your “inverse” sprite shape with some color
  • set it to a unique layer
  • add a new camera and set it to only view that new layer
  • render the cameras output to a render texture
  • in code, use the rendertexture and generate a new sprite from it using tex2d
  • apply that sprite in the same position as your sprite shape on a new sprite mask
  • make another tiling sprite using the fill sprite you want as your wall, set it to draw only outside the mask, or set where you want the “hole” in another sprite shape and set that to only draw outside the spritemask.
  • make a duplicate of your sprite shape and invert the path tiles
  • run scene :slight_smile:

I’m doing this at runtime and works perfectly, you could probably get it to run in edit mode too.

why don’t make spline or such tools as intuitive as Ferr2D or
Spline Terrain 2D: https://assetstore.unity.com/packages/tools/sprite-management/spline-terrain-2d-122383

Also, I don’t find many people use sprite shape is there any reason? Also if you look at assets using spriteshape there is very little when compared to tile sets. I think unity developers can do much better with spriteshape. Hope it gets better and popular.[

](Spline Terrain 2D | Sprite Management | Unity Asset Store)

4 Likes

Hi,

I am using 2D Sprite Shape 5.1.2 in my game, Unity version 202.3.7f1

The sprite sprites are dynamic, which are composed of 2D physics rigidbodies… and are modified at runtime

I have fill tessellation enabled, since it optimizes the CPU greatly and gives me a good 60FPS on low-end devices. My SpriteShapes fulfil the criteria for “Fill Tessellation” which is
1 - Dynamic sprite Shape
2 - No overlapping edges or duplicate points

Yet, the game gets stuck randomly on all the platforms, be it Unity editor, Android or iOS device. And there are no crash logs. To me it seems like the Fill Tessellation Jobs run into some “race conditions”

Could it be that I am modifying the shape in “Update” method, which causes this issue? Should they be done in “FixedUpdate” because of physics or LateUpdate?
Or do I need to call some method after modifying the shape? This is how I can updating the shape

private void Update()
{
        int totalPoints = ShapeSpline.GetPointCount();
        for (int i = 0; i < totalPoints; i++)
        {
            ShapeSpline.SetPosition(i, edges[i].transform.localPosition);
        }
}

Thank you and looking forward to your reply

I would suggest adding it on LateUpdate. Could you also please submit a bug report with a simple repro project please ? That will be very helpful in analyzing the issue. Will take a look asap. Thanks.

1 Like

Hey thank you for the quick reply, I will try this and see how it works. I will try to file the bug sometime next week since I need to strip out this part from the project

Hi, first of all sorry I haven’t yet made the sample demo the issue, but I opted on not using the Fill Tessellation option.
While the game works fine, I am running into another issue. I get the follow exception

InvalidOperationException: The previously scheduled job SpriteShapeGenerator writes to the Unity.Collections.NativeArray

Maybe this is the problem here?

Thank you and looking forward to your reply.

Hey were you able to find a solution for the exterior & interior image?

1 Like

see my solution [above. ]( https://discussions.unity.com/t/774477 page-4#post-7180483)

Why doesn’t Sprite Shape respect the editor’s grid snap toggle?

In my project I found that I need to snap practically every point in every shape to the grid. There’s a lot of shapes in a level, as you can imagine. This is currently a very, very painful process:

Every time I select a shape for editing I have to click the Snapping checkbox (which always resets back to unchecked whenever a shape is selected). I have a 5K display. The checkbox is tiny. I have to do this to every shape every time I want to change something.

Sprite Shape goes through the trouble of disabling the global grid snapping option when the shape editing button is clicked. The setting is then very politely turned back on when the user exits shape edit mode.

In my opinion the snapping toggle should not be in the inspector in the first place. It’s not a persistent per-object setting, the checkbox is only visible while the shape is being edited in the scene. Moving points and snapping them to the grid should be considered tool-level functionality that should respect the settings of the editor’s grid snapping settings, as one would expect.

Sprite Shape does use the unit increments specified in the editor’s grid options for snapping, it just overrides the current state of snapping and decides that it should be off, always. Is this just a bug?

I tried to hack a custom keyboard shortcut for checking the snapping option in the inspector, but the logic is buried so deep in the code that I gave up on it… I did discover that there’s a few handy undocumented(?) keyboard shortcuts for Sprite Shape, though (search for spriteshape in Shortcuts to see these). Alas, no shortcut for snapping.

2 Likes

Agree especially when Snapping is heavily used… We are working on this and will be posting an update soon. Will update this thread too. Sorry for the inconvenience caused.

2 Likes

This is great news, much appreciated!

@Venkify any plans on adding this feature? Other terrain tools like Ferr2D and Spline Terrain 2D have this

Possible to do with the workaround mentioned, but that is just extra work and processing

1 Like

Sorry for the late response, me and my team are still struggling with interiors/inverted shapes (since start of this year). We are creating rooms with venkifys workaround below (but hoping every month there comes a fix/better solution. I still don’t get why Unity won’t add a checkbox to invert shapes):

2 Likes

Hi! Another feature request…

Can you add an option to re-align pivot to at least center? While creating a shape, almost all the time the pivot goes way off

1 Like

This would be great! In the meantime, I do have this script that works pretty well… It doesn’t keep the terrain in the same place but it does center the pivot.

Just add this script to your Editor folder and use it like this:

bhii87

Hope it works!

7487933–921647–SpriteShapeControllerEditor.cs (1.24 KB)

2 Likes

Thank you so much for this !
The pivot points were driving me insane for days xD

1 Like

Thanks, works well!

1 Like