Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

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:
    55
    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:
    94
    Anyone?
     
  3. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,923
    Tymianek likes this.
  4. Tymianek

    Tymianek

    Joined:
    May 16, 2015
    Posts:
    94
    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:
    1
    It works like a charm! Thanks.
     
    Tymianek likes this.