Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Is there a quick way to snap SpriteShape points to a grid?

Discussion in '2D' started by BlueInfinity, Sep 25, 2023.

  1. BlueInfinity

    BlueInfinity

    Joined:
    Jan 24, 2022
    Posts:
    15
    I've got a SpriteShape and want to snap its points based on the defined grid. I know how to snap objects, but couldn't find any way to do the same with the points of SpriteShape. Is there functionality to do this, either within the SpriteShape package itself, or via an external tool, or do I have to code an editor script to handle this myself?
     
  2. Chubzdoomer

    Chubzdoomer

    Joined:
    Sep 27, 2014
    Posts:
    106
    When you select your Sprite Shape object and click the Edit Spline button, you should see a "Snapping" option in the Inspector. Once you turn it on, it should make your points snap to the grid as you move them around.

    Something important to be aware of is that your Sprite Shape object's position directly affects where the grid-snapping takes place. If you leave your object at 0,0 for example, and your project's Grid Snap setting is at 0.5, then you'll be able to neatly snap points to X and Y positions of 0.5, 1.0, 1.5, etc. just like you'd expect. If on the other hand you have your object at a strange position like 0.115, 0.813, then your points will end up being offset. And so your X position snap points will end up being 0.615, 1.115, etc. (adding 0.5 each time). It's a little confusing to try and explain by way of text, so I recommend experimenting with it yourself to see how the Snapping behavior differs based on your object's position.
     
    Venkify and BlueInfinity like this.
  3. BlueInfinity

    BlueInfinity

    Joined:
    Jan 24, 2022
    Posts:
    15
    Thanks! I seem to have missed the snap option, since it wasn't visible before I clicked "Edit Spline", and I assumed you could snap the points by holding CTRL like other objects.

    I completely understand what you mean by offsets, and this won't be an issue since I'll be snapping all objects to 0.5 grid as well.