So… There is a single value called gridPosition attacked to a component called GridItem. There is a Editor window that is used to edit these items ( Item Size, Transform offsets, position, gizmo stuff etc.) when such an item is selected. When the user has this window open, and is adjusting the transform of the gameObject, the window snaps the transform to the grid, based on some values from a gridManager(grid start, grid unit sizes) and updates the grid position based on this, as this value is used to draw gizmos, and generate box colliders on certain objects at runtime.
When the grid position value is modified directly in the Inspector, the changes are fine. When I change the values through the Editor Window(which happens when you move an object with the move tool) the values revert to whatever was the last value that was set in the inspector was. If there was not a value set in the inspector, it revert to the prefab if it has one. the value is modified before Awake is called on the script.
This behavior is only seen on Grid Items that are part of a prefab.
Cases:
Case 1:
So Prefab Grid Item Grid Position is set to Value A;
If we move an instance of the prefab with the move tool, the item is moved, and Grid Position is set to Value B.
On test, Awake states the gridPosition is Value A. On test exit, Grid position is Value A.
Case 2:
Again a prefab is created waith values being Value A.
The grid position is changed directly in the inspector, and a context menu function adjust the transform to the new grid position, with Value Being B.
On test, value is still Value B.
If we move the item with the built in move tool, to Value C, then test, the value return to B by Awake, and is still B when the test concludes.
Case 3:
A Gameobject has the gridItem behavior attached to it, the gridPosition is A. It is not an instance of a prefab.
It is moved with the Move Tool, the gridPosition updated by the window, to grid Position B.
On test, the grid Position is B.
Case 4:
A game object that is not an instance of a prefab has the GridItem behavior attached to it, with gridPosition set to A. Item is moved by modifing values in the inspector, then transform is told to update to new position. Grid Position is now Value B. On test, Grid Position is B. Item is then modified using the window again, to Grid Position C.
On test, grid Position is C.
So basically, the determining factors of the bug are
A) The object must be a prefab.
and to a lesser extent
B) The value must have been edited by the gridwindow.
((B is lesser, because is A is false, B does not matter, it works correctly(See Case 3/4)))
For this Bug: The grid position is set to the last value set from the inspector. If one does not exist, the value is set to the prefab value.
This system worked before we updated to Unity 3.5(Pro)
I can make some workarounds that deal with the symptoms of the bug, like updating the grid position based on transform at awake and when the game returns from test, however, I would really like to find the source of this bug.
Thank you in advance. Also, if you think I should make a new post, let me know. This is my first time posting a bug to Unity Answers, so I’m trying to be slightly conservative.
This is a pretty complex problem to understand. Maybe someone else will have some insight, but in the meantime I would suggest that you isolate this in a separate test project and keep reducing it until you get a very simple and clear example with easy steps to reproduce the problem. You will at least then have a project you can submit with a bug report to Unity, or you may discover an obscure bug in your script.
– Steven-Walker