Home > unity > most efficient way to create a grid system in unity

most efficient way to create a grid system in unity

May 19Hits:2
Advertisement

I'm creating a little tower defence game to get myself acquainted with unity.

At first I was going to emulate a grid system by capturing touches / mouse clicks and rounding the coordinates to the nearest whole numbers. This is very low cost and works well for placing things, however I'm a bit of an AI geek and I've decided to make a more tangible grid so that the agents can run searches on it for pathfinding.

For this I'll need a grid of nodes and for those nodes to have a bit of information attached. Would it be a much better idea to do this entirely in code? Or could I get away with placing actual cubes in a big grid on the map?

This would certainly be easy as then I could ray cast against them - but I've tried this and rendering that many cubes slows down the game a lot!

I suppose my question is - is it unnecessarily expensive to have a load of cubes set up like this, but not rendered? Or should the cost of having a load of cube shaped collision volumes be only marginally more expensive than emulating this in code? (if at all...)

Also as a side question - should I be able to render say, 200 cubes and have a smooth game? Am I missing some instancing options? I presumed things would be automatically instanced.

Answers

I am going to attack your question out of order, partly because I am seeing issues with the way I think your attacking the problem.

This [cubes] would certainly be easy as then I could ray cast against them - but I've tried this and rendering that many cubes slows down the game a lot!

I don't know why this would be slow, unless you are constantly creating, altering, and destroying these cubes at run-time, but even then 200 cubes is child's play to unity (when you start getting to say 10,000 simultaneously interacting items then Unity can start to have problems.

You don't need to have physical "objects" in your world to ray-cast between them. you simply need to have objects in your world (Empty GameObjects)

I suppose my question is - is it unnecessarily expensive to have a load of cubes set up like this, but not rendered? Or should the cost of having a load of cube shaped collision volumes be only marginally more expensive than emulating this in code? (if at all...)

200 cubes (even 200 RigidBodies) is not that much in Unity. on the part about emulating in code depends on what you absolutely need your nodes to know.

Also as a side question - should I be able to render say, 200 cubes and have a smooth game? Am I missing some instancing options? I presumed things would be automatically instanced.

instancing in Unity is based around the prefab system (basically make up your thing then create a prefab, and then use it again, and again in your game/scenes)

At first I was going to emulate a grid system by capturing touches / mouse clicks and rounding the coordinates to the nearest whole numbers. This is very low cost and works well for placing things, however I'm a bit of an AI geek and I've decided to make a more tangible grid so that the agents can run searches on it for pathfinding.

if you can mask your entire game level/scene in a fixed grid you should in theory be able to use standard grid traversal, but all of your book keeping will probably need to be specificly value centric, and in the end run this is not going to be very clean/efficient.

For this I'll need a grid of nodes and for those nodes to have a bit of information attached. Would it be a much better idea to do this entirely in code?

yes, no, maybe it depends on what information you absolutely need your nodes to have (the simplest node I can think of for a tower defense game is is a point, a bool occupied, and a bool reachable)

Or could I get away with placing actual cubes in a big grid on the map?

Why would you do this? I see no value besides having something that you can physically see in the editor, and when it comes time to run the game you wont be doing anything with these cudes as cubes, so why have them in the first place if your just going to take away their collision, and rendering. All you have left is a transform which you could have right away by having empty gameObjects.

the easiest way to do nodes in Unity is to create empty gameObjects(mainly for the position), and then give them a script for all the variables you need, and then put all those nodes onto their own layer.

EDIT (In response to request for more detail in comment):

Isn't making a cube, and taking away its collision, and rendering the same as creating an empty gameObject?

yes, and no. yes its the same in terms of physics, and rendering, but no in terms of the engines book-keeping. every fixedUpdate (especially in non-release mode) the system takes all components that a object has, and the same for its children, and puts them to be calculated, and then if any of those are not active throws it away. so its still trying to do stuff with the inactive components its just not that much. if you multiply this enough times it can amount to maybe an extra half second per frame, but that's probably up there.

Are empty gameObjects by default cube shaped?

No. from an application standpoint think of an empty gameObject as a modifier that is modifying something, or nothing. I can create an empty gameObject, and then move it around the world/scene, and then I can rotate it, and scale it, but if it doesn't have any children nothing happens, but the changes are recorded. then if I take, and create a sphere, and make it a child of that empty gameObject then that child will take on those modifications, and have its own values stored with respect to its parent, but in essence of physical logic that empty gameObject is nothing (no size, shape, or anything), but it does have a transform, and can receive components.

Because if they're not the benefit of a grid of cubes would be the foundations of a navMesh.

your right to a point. when I say the word grid most people think about drawing boxes, and having all of those boxes be uniform dimensions, but when we go to put things in those boxes all we really care about is a point in space (usually the center for 3D, but for 2D sprites top left) so if we take away the boxes, and instead only keep those points in space we still have a grid, we just don't have boxes.

You can still use all your favorite pathfinding algorithms with points/nodes that you did with a grid, and more. Calculate the distance between them, and apply a weight to that distance (dijoksra, and A*), Allow the agent to consider multiply nodes at once (fuzzy logic), track the players movements through a set grid pattern, and then give a weight to a set of rules that correspond, and then have the agent chose a response based on the highest weight (exert systems).

A grid is just a visual representation that the player may never see (unless you actually want to draw those boxes on the screen, in 2D ok, but if your in a 3D perspective that can get confusing quickly especially if the camera can rotate).

could you explain what you mean when you said - 'but all of your book keeping will probably need to be specificly value centric, and in the end run this is not going to be very clean/efficient."

I meant having each agent have to do the same rounding that you do for your mouse clicks which is very value centric, and you end up having to do a lot of the same clean up work of hard coded values, and you get the same end run checks as when doing if(X>300){//do something}. but if you do just find the nodes nearest to here (its up to you if you want diagonals), and if you really wanted to you could use the same logic for mouse clicks instead of rounding values just ray-cast to find the nearest node.

Tags:unity

Related Articles

  • most efficient way to create a grid system in unityMay 19

    I'm creating a little tower defence game to get myself acquainted with unity. At first I was going to emulate a grid system by capturing touches / mouse clicks and rounding the coordinates to the nearest whole numbers. This is very low cost and works

  • How to create a grid system on a tri fold leaflet or brochure in InDesign

    How to create a grid system on a tri fold leaflet or brochure in InDesignSeptember 11

    I'm new to working with grids and tri folds, and I was wondering if anyone could help me out? As you well know when creating a tri fold, the fold in panel width becomes a different size than the other two panels. And from some templates I've download

  • Most efficient way of creating a grid in HTML with CSS?May 2

    So my problem is this, I need to create a grid that in each cell there should be a 0 or a 1. These cells when clicked should toggle between 0 and 1. When hovered It should show the coordinates (ex: 1,5). Now the only way I got this to work was by cre

  • Efficient way to create picture grid

    Efficient way to create picture gridAugust 14

    Suppose you're a photographer who works in Photoshop and Lightroom, and who wants to create a borderless "contact sheet", a grid of different photos with pixel-perfect alignment of the edges of each image. Perhaps the obvious way, using Photosho

  • How to create a "Lasso" system? - (Unity - Mobile)

    How to create a "Lasso" system? - (Unity - Mobile)February 13

    I've been working on a personal game project, and I have though in a lot of ways to do a mechanism like a lasso but unfortunately, I've had no success. I'd like to make a system which every time the player draw a circle around the object, it must be

  • How to quickly and easily create a grid with Adobe Photoshop?

    How to quickly and easily create a grid with Adobe Photoshop?November 22

    Suppose I need to draw a grid in Photoshop, each square being the same size, and a certain amount of pixels tall and wide, and the grid lines having a certain pixel width. Like this: Currently I do this by drawing one square, copy+pasting+moving+merg

  • Creating a Responsive Grid System with Susy and BreakpointDecember 9

    The big appeal behind CSS frameworks (like Bootstrap and Foundation) is that they come with a responsive grid system all set and ready to go. The downside is that you have to be content with their column count, the width of their gutters, and all the

  • How to create interfaces in a graphics editor for responsive grid systems considering that they aren't pixel-perfect? September 7

    Any responsive CSS grid system uses long decimal point percentage values for columns' width (e.g. "16.66666667%"). I don't understand how to lay out the grid in Photoshop, because elements of the interface will either be longer, or shorter than

  • A Creative Grid System With Sass and calc()March 27

    Before we even get started talking about Sass and the code for this project, let me remind you this is no more than a quick experiment which by no means should be used in a live context. So what follows is only a proof of concept of what we could do

  • Simple grid system made out of CSS columnsApril 15

    I have been researching and experimenting with HTML5 and CSS3. I was aiming to create a very simple but efficient tiled gallery / grids. So some sort of grid system that I can layout anything inside. Below is what I have created, what are your opinio

  • I'd like to create a grid of PCs on which to run virtual instances of WinXP. What is the best method?April 9

    I'd like to create a grid of PCs on which to run virtual instances of WinXP. What is the best method? I have a number of dual-core intel desktops and I'd like to run a few of them to create a high availability environment on which to run one or more

  • Looking for an efficient way to create polished scientific graphics

    Looking for an efficient way to create polished scientific graphicsOctober 13

    I'm looking for a professional and efficient way to create scientific graphics. There are basically two types of graphics I want to create (and maybe not a joint approach works for both): Plots of functions and data, and free body-type diagrams. Unti

  • Mixing the classic type size scale, grid systems and modular scalesNovember 25

    I'm coming from a programmers background and just trying to understand how sizes should relate. I read in the book "designing for the web" that these are the classic type sizes and text set in these size should look better if typeset correctly.

  • Designing for the Web: Templates and Grid Systems

    Designing for the Web: Templates and Grid SystemsDecember 12

    Continuing on from the previous article in this series, Designing for the Web: Resolution and Size, we cover some helpful and important factors while creating a template for designing a website. In this article, we will cover some important issues an

  • DesignFestival: Designing for the Web: Templates and Grid SystemsDecember 13

    Continuing on from the previous article in this series, Designing for the Web: Resolution and Size , we cover some helpful and important factors while creating a template for designing a website. In this article, we will cover some important issues a

  • Getting: org.opengis.referencing.NoSuchIdentifierException: No transform for classification "Transverse Mercator Zoned Grid System" with geotoolsApril 22

    Using geotools I've been trying to create a referenced envelope after converting/reprojecting from WGS 84 to UTM with specific zones and it seems that either I need to do something with authority factories or figure out some kind of a workaround for

  • Adding custom layout to Omega child theme breaks grid systemSeptember 10

    I'm trying to create an new responsive layout in an Omega child theme. To do this I copied the grids variable from alpha.info into MYTHEME.info and added my layout (called 'narrower') based on the existing pattern: grids[alpha_default][name] = Defaul

  • Creating a license system based on asymmetric encryption (RSA or ECDSA)May 30

    I've spent a couple of days researching the topic of creating a license system for my desktop software. While I fully understand that there's no perfect copy protection, this approach seems to have the best balance for me. There are a couple of detai

  • Bootstrap's Grid System vs. Susy: A Comparison

    Bootstrap's Grid System vs. Susy: A ComparisonAugust 29

    There are a lot of grid frameworks for us the to choose from while developing websites nowadays. Of the many frameworks, one of most loved and yet most hated framework is definitely Bootstrap. Today, I'll like to introduce you to a slightly lesser kn

  • creating precipitation gridOctober 20

    I am trying to create a precipitation grid for my meteorologic model. The problem is that, I do not know what are the things I should have for me to create the grid. Can anyone tell me what are the requirements and how to run the process? I am using

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.853 s.