Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Help Wanted How to change editor grid size by script?

Discussion in 'Editor & General Support' started by Tom-Kazansky, Dec 15, 2020.

  1. Tom-Kazansky

    Tom-Kazansky

    Joined:
    Mar 9, 2015
    Posts:
    14
    Hi,
    Is there a way to change the grid size in the editor by using script? I mean the "Grid Visuals" in Grid and Snap window.
    unity3d-grid.png
    the game designer in my team want some utilities to help him speed up level designing, he want to change these settings by some preset value (with a button click) and manual input.

    I can change the snap settings with EditorSnapSettings but I cannot find any API to change the grid size.

    I'm using Unity 2019.4.9f1

    Thank you for reading,
    Tom.
     
    Tymianek likes this.
  2. Tymianek

    Tymianek

    Joined:
    May 16, 2015
    Posts:
    85
    Anyone?
     
  3. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    7,242
  4. Tymianek

    Tymianek

    Joined:
    May 16, 2015
    Posts:
    85
    Solution: Use Reflection to get the Grid Size property
    Code (CSharp):
    1. Assembly assembly = Assembly.Load("UnityEditor.dll");
    2. Type gridSettings = assembly.GetType("UnityEditor.GridSettings");
    3. PropertyInfo gridSize = gridSettings.GetProperty("size");
    4. gridSize.SetValue("size", new Vector3(1,2,3));
     
unityunity