Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Aliddel · Jun 19, 2013 at 03:22 AM · gridgrid based game

Problem making a grid for a TBS game

The way im making the grid at the moment is using a very simple script attached to a bunch of game objects (each representing a tile).

  public class GridTile : MonoBehaviour {
         public GridTile north;
         public GridTile south;
         public GridTile west;
         public GridTile east;
         public int defB onus;
         public int movCost;
         public bool isAccessible = true;
     }


I was wondering if anyone knows of a better solution, maybe something using planes. Because as it stands, its pretty costy to load 40+game objects per stage. Thanks in advance.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DannyB · Jun 21, 2013 at 12:30 PM

What you are doing is perfectly legitimate and fine. Loading 40 objects to a scene is a piece of cake for Unity. When you are building a board game, each tile should be an object of its own, as you are trying to do.

If you see any performance problem, it is not because of the quantity, but probably because of the quality of code.

Make sure that your objects are as light as possible:

  • in terms of loading time (whats in your Start() and Awake())

  • in terns of memory/drawcalls

  • and in terms of what it does in its Update()

For further optimization (although I would recommend against premature optimization), you can consider deactivating some tiles if they are hidden from view, and/or replacing Update() with your own less frequent game loop (with StartCoroutine())

Finally, if you have a specific reason why you think what you are doing is wrong, please be more specific.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by lonevetad · Oct 09, 2017 at 10:22 AM

Could be out of topic, but consider to have an enumeration of directions (the four north-south-ecc and maybe also the other diagonals) and have an array of GridTile pointers. In this way your algorithms would be more easy to be written. For example, the "turnBack180Degrees" could be (in Java-like, i don't know how C#'s enumerations works) :

 enum Directions {
     North(0,1), South(0,-1), West(-1,0), East(1,0), N_E(1,1), S_W(-1,-1). N_W(1,-1), S_E (-1,1);
     //add stuffs useful for a matrix representation of your grid of GridTile
     final int xOffset, zOffset;
     Directions( int xo, int zo){
         xOffset = xo;
         zOffset = zo;
     }
 }
 public static final Directions[] valuesDirections = Directions.values();
 
 public static Directions turnBack180Degrees( Directions dir ){
     int ordinal;
     ordinal = dir.ordinal();
     return valuesDirections[ ((ordinal & 0x1) == 0) ? (ordinal +1) : (ordinal-1)  ];
 }

Using that enumeration (and its array of values) you can iterate over all of GridTile's neighbour (this is usefull on pathfinding algorithms).

 public static GridTile getNeighbour( GridTile[][] matrix, GridTile node, Direction dir ){
      return matrix[ node.z + dir.zOffset ][ node.x + dir.xOffset ];
 }

Hope it helps!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Grid Letter Box is not expanding, 0 Answers

2D Tile Map Question 0 Answers

How to handle Grid Boxes properly? 1 Answer

How to Shift cells of a grid (regarding TileMap) 0 Answers

How to only show objects in range ? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges