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 maikkel · Feb 20, 2012 at 09:46 AM · arraysobjectsgrid

Grid Based Map Object-Array vs Arrays only

I'm building a game using a 3d grid based, procedurally generated world (same world concept as Dwarf Fortress/Towns).

For the Blocks i use a 3D array of Block instances (normal class, not GameObject), like this: Block[,,] blocks = new Block[sizeX,sizeY,sizeZ]. The block object contains all relevant block info like positions, and bools like "isWalkable" and vertice positions for rendering (they are then combined into "Chunks" for rendering) This runs quite well, even with a million Blocks (128x128x64)

My question: Would it be better to store the data in seperate arrays? For example have arrays "BlockWalkable[,,]", "BlockVerts[,,]"...

This way i could get rid of Objects.

I'd like to get rid of as much overhead as possible to make room for implementing pathfinding later... Would there be any advantages for lookups for example? Or memory savings? I woult test it but it would require quite a large rewrite, so i thought i'd ask first.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by senad · Feb 20, 2012 at 10:05 AM

I do not remember the numbers exactly, but the overhead for having a class in say C# is in the magnitude of a few bytes. If you have a few million objects that makes a few megabytes, it could still be tolerable on the PC. Depends a lot on your memory budget.

The performance may suffer if you use methods (and I guess properties count as methods) to look up values as opposed to just look up a value in an array.

However, my opinion is this: the readability (and maintaining and testing) of your code will likely be much harder if you do these optimisations. So if it was my project, I would definitively do some profiling to identify the bottlenecks before I start optimising.

Comment
Add comment · Show 1 · 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 maikkel · Feb 20, 2012 at 11:36 AM 0
Share

Thanks for the information. I think I'll leave it as it is for now (with Objects) and if i REALLY need to optimise something I'll look into it again.

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

6 People are following this question.

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

Related Questions

What is the maximum amount of objects that can be stored in an Array or List without causing any error? 1 Answer

Creating custom objects? 2 Answers

How to get the size of an array of object? 2 Answers

Trying to Create a grid for a matching game 0 Answers

Beginner : Random gameobject from array 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