- Home /
Creating a grid for sceneview and in game,Making a simple grid map editor for Sceneview
I want to create a grid of tiles that are capable of storing and relaying info for pathfinding. Ie. This is a wall and therefore not walkable, or spawn an object on this tile for it to be picked up by a character later, or direct a character to walk to this tile, etc. I want it to be grid-based so that movements are fixed to the tiles.
Now I have a general idea of how to do most of this. But I don't know how to create one in scene view, as I want to be able to manually place objects, wall, and characters on it, the game doesn't need to have procedurally generated levels. And having to design a level with code alone is just tedious.
I know gizmos can be used to create a grid in scene, but can I rely on it to be the basis of what I'm trying to do in game? If not, what method should I use?,I'm new to Unity and coding in general, but I know how to use loops, functions, pointers, array, etc. I just don't have enough experience to figure out the programming logic just yet. So I'm looking for advice that points me to the right direction so I can do some more research.
I want to make a simple 2d tile based movement/ pathfinding system for my game. I know how to use loops to instantiate a grid of tiles made up of different types, but I can't use it as a map editor since it only runs when the game is running. I want to be able to manually hand place objects and walls in the sceneview, with a grid underneath so I can make sure placement of objects are precise.
So another option is to use Gizmos to draw a grid. But my question is if I use Gizmos, can I rely on it to be able to store data for me while the game is running? For example, if I want my game to be able to detect and relay which tile a character is on right now for pathfinding reasons, or which tile is a wall and therefore not walkable, or a chair is on this tile so walk to this tile to seat, or spawn an object on this tile for someone to pick it up later, etc.
Or am I thinking the complete wrong way? Is there an easier method to build my level?
Answer by rvilgalys · Nov 26, 2017 at 08:33 PM
I think you'd want make a 2d array of your tile data for the easiest lookup, possibly in a ScriptableObject. Gizmos are really just for drawing things in the scene view, not as much a good place for data handling. A small editor script attached to your prefab tiles could talk to the 2d array to Add/Remove with OnEnable() and OnDisable().
Thanks for the suggestion, but I think I found a simpler solution. I can keep all the code for the tiles generation, and just use the same logic to display an identical gizmo to see where the levels will be for the scene view. Don't know why I didn't think of that earlier...