Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Right way to show grid?

Discussion in 'General Graphics' started by ian0198, May 18, 2019 at 3:15 AM.

  1. ian0198


    May 4, 2019
    I want to show a square on top of the floor so the player can place some objects in my game. I was wondering about the performance of instanciating a tile using the player's mouse position. Is a game object the best way to show this UI stuff? Or does unity have another resource that can better tackle this problem?
    I've got the right result:

    The used code:

    Sorry if this is in the wrong place in the forums or something.
  2. Antypodish


    Apr 29, 2014
    Use plane with repeated texture of cross/square.
    Or write shader, to generate grid.
    Or use asset store, to find existing solutions.
    xVergilx likes this.
  3. Sh-Shahrabi


    Sep 28, 2018
    Your link just opens giphy for me. So I am not sure what it is that you want. However if you want a grid repeating itself, the best way would probably be sampling a tiled texture. The using shader method which @AntySK mentioned, is fun and gives you easy control over line thickness and such. But the main issue is aliasing as the camera moves and also along steep angle of the plane. The repeated texture method he mentioned is the best way since you can use mipmaps and anisotropic filtering.

    The issue with that method is that you are losing control over line thickness. Another method is to use the using shader to generate grid method, but sampling a gradient map to determine the edges of the grid line. Like this you still have easy control over the thickness, but also dont have aliasing issue as your gradient map is receiving mip maps and anisotropic filtering
    Antypodish likes this.
  4. bgolus


    Dec 7, 2012
    This is the right place, though I think you confused people by talking about grids, and posting a link to a page of links to your gif rather than to the gif itself.

    What you're doing is fine, as long as you're not instantiating a new tile highlight for every grid position. Instantiate one, then keep it around and move it & hide/unhide it as needed. If your world is a nice flat plan, this really is probably the best way to go about it. The alternative would be to use a projector, which will let it conform to non-flat surfaces, but will be more expensive.