I’m working with pixelart and tilemaps. Thus I also work with the snapping option to ensure pixel accurate placement.
I used to have Grid Size set to 0.03125 (1/32 since that’s the tile size and grid cell size). This worked in all scenarios. Be it within the context (e.g. as child) of a grid or without.
Since updating to Unity 6.0 snapping within the grid still requires 0.03125, to work correctly, but as soon as I work outside of the grid context the snapping only works when set to 1.
If this change is intended, I can see why but this leads to significant issues with my workflow and makes it error prone.
I am now trying to figure out a way to make snapping be consistent again. I am hoping I missed some option or workaround?
I tried some things and did notice that as long a the grid cell size is set to 1, snapping becomes the same again, but then the tilemaps no longer work (the tiles overlap).
This is one of the grids I’m working with:
The difference is snapping occurs when one sprite is a child object and one is not.
My sprites are at 1 pixel per unit.
Numerical example:
-snapping grid size: 1
-transform outside of grid 0>1
-transform within grid: 0>32
Edit:
I figured it out: A colleague made a neat little script that solves the issue.
using UnityEditor;
using UnityEngine;
using UnityEngine.Tilemaps;
[InitializeOnLoad]
public static class GridSnapAutoSetter
{
private static readonly Vector3 defaultSnap = new Vector3(1f, 1f, 1f);
static GridSnapAutoSetter()
{
Selection.selectionChanged += OnSelectionChanged;
}
private static void OnSelectionChanged()
{
GameObject selected = Selection.activeGameObject;
if (selected == null)
return;
// Try to find a Grid component in the parent chain
Grid parentGrid = selected.GetComponentInParent<Grid>();
if (parentGrid != null)
{
// Apply the grid's cell size to the editor snap settings
Vector3 cellSize = parentGrid.cellSize;
float x = cellSize.x != 0 ? 1f / cellSize.x : defaultSnap.x;
float y = cellSize.y != 0 ? 1f / cellSize.y : defaultSnap.y;
float z = cellSize.z != 0 ? 1f / cellSize.z : defaultSnap.z;
EditorSnapSettings.move = new Vector3(x, y, z);
}
else
{
// Reset to default snapping if not under a Grid
EditorSnapSettings.move = defaultSnap;
}
}
}

