I'm trying to programmatically add tiles and objects to a 2D scene. I have a tilemap with a lower number layer and an empty game object with a higher number layer that will contain the objects.
Problems:
Example for one cell in the grid:
// Set tile for the tilegrid
Vector3Int tilePos = new Vector3Int(i, j, 0);
groundMap.SetTile(tilePos, groundTile);
// Place object as if it were standing on that tile cell
Vector3 objPos = new Vector3();
objPos.x = 1.0f*tilePos.x + 0.5f;
objPos.y = 1.0f*tilePos.y + 0.5f*objectHeight;
GameObject obj = GameObject.Instantiate(objectPrefab, objPos, Quaternion.identity) as GameObject;
obj.layer = objectParent.layer;
obj.transform.SetParent(objectParent.transform);
Solutions?
Disclaimer: I'm a programmer but still pretty new to Unity. I tend to do as much as possible in the scripts, but I am very open to learning more about Unity's native tools.
Layer != Sorting layer. Sorting layer on renderers rather than the layers just on the game objects are what actually control what gets drawn on top.
Edit > Project Settings > Graphics > Camera Settings > Transparency Sort Mode > Custom Axis ... > Transparency Sort Axis > (0, 1, 0)
Source: https://answers.unity.com/questions/1098203/sorting-layers-according-to-y-axis.html