- Home /
Dynamic Grid - A design problem.
Hi,
I want to create a dynamic grid for my project. Simply put, I want a grid on a plane that is dynamically redrawn in every update, according to the size and location of the object (a rectangular shape) that is placed on the plane. For example in the begging there is no grid on the plane, but when i drag my object on it, I want a grid to appear that takes the objects position as reference point (to adjust itself so that make sure the recent object fits in a cell perfectly) and dimensions of the object as its cell size. I want to use it as a guide for the user. When the object is dragged around, the grid is also moved or redrawn. Grid disappears when the object is locked to the plane. Similarly, when a new object is dragged on the plane same procedure applies.
I cant think of a good, performance friendly solution for this. Is creating the grid cells as a game objects a good idea ? I might need to access to the information of any cell as in location or size later on so the whole grid cant be just a texture.
Please share your insights and any suggestion would be appreciated.
You can have a second plane with a grid texture on it, then scale that plane in proportion to your object's size. You can possibly save whatever data you need about the cell in a struct array for later access and modification.
You can get the size of the object by accessing it's bounds via collider.bounds.size.x
and collider.bounds.size.z
First of all thanks for the answer. The plane size is fixed, so if i scale the texture layer plane, it would be wrong. $$anonymous$$aybe I can keep the texture plane idea and try to draw the grid dynamically somehow (dont know how). The problem begins where I drag my object around on the plane, and the grid should follow the object. I mean practically the object could be put anywhere on the plane, but then the grid should be adjusted. This may sound weird but its a part of the whole idea..
Do you think if I get to work the idea of dynamically drawing the grid in each update, would it be killing the performance ? Or even worse, if I make up the grid out of game objects (one for each cell) and remove and recreate them after every update. (re positioning might be tricky..)
Creating and destroying an array of game objects every frame will definitely kill your performance.
What I meant to do is keep two planes, one to represent the dynamic grid. You can make it a child of the object you drag on the placement plane so it will follow it around, then upon placement of the object on the placement plane, break the parent relationship of the grid plane and move it out of sight, perhaps even disable it altogether.
If the grid plane has a texture with fixed cell size, let's say 1x1 Unity Unit (1 meter) to make it easier to manipulate, then resizing the plane will result in the grid increasing or decreasing in size accordingly. Alternatively, you can just adjust the tiling of the texture to achieve the same result with far less potential bugs (scaling can cause a lot of funky stuff)
O$$anonymous$$, finally I came up with a design like following, inspired from what you said as well
1) Create a 'big' unit grid.
2) Resize it wrt to the size of the object.
3) relocate the grid so that its center cell will match up with the object.
4) $$anonymous$$ask the parts of the grid that are out of the place (from orthogonal cameras perspective)
5) for each update just relocate the grid and adjust the visibility of the cells according to the step 4.
Havent tried it yet but I see it could work. Just for the record, I did try the creting and destroying at each update solution adn traced the FPS rate, it dropped drastically after 10 seconds or so. Wasnt a good idea, tho thats why I asked the quiestion :)
Your answer
Follow this Question
Related Questions
can anyone tell me about making grid manualy 2 Answers
Fastest way to draw a grid of textures 2 Answers
What is the best way to create 3D tile based levels in Unity ? 1 Answer
Performance While Loading Map 2 Answers
Terrain Performance on Shaded Terrain 0 Answers