Search Unity

Question 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:
    58
    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:
    97
    Anyone?
     
  3. Tymianek likes this.
  4. Tymianek

    Tymianek

    Joined:
    May 16, 2015
    Posts:
    97
    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));
     
    WhaleForge, Ambivert and rtsonneveld like this.
  5. WhaleForge

    WhaleForge

    Joined:
    Nov 9, 2015
    Posts:
    3
    It works like a charm! Thanks.
     
    Tymianek likes this.