please make it possible to use the Sprite Shape Renderer as a Sprite Mask or,
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
@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
Iâm doing this at runtime and works perfectly, you could probably get it to run in edit mode too.
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.[
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);
}
}
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.
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
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.
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.
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):
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: