Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 GoMeteoroGo · Oct 15, 2015 at 01:11 AM · gameobjectarrays

Will a large array of game objects slow my game down?

I'm working on a 2D, top-down action adventure game. It occurred to me today that it could be very useful to use a large 2D array of game objects to represent each level, where each element in the array represents an integer value on a grid used to place objects. For instance, this could be used in collision detection: the moving object could check the array elements adjacent to them, and as long as they are null, they are free to move. It could also be used as a very fast alternative to raycasting.

My concern is that these arrays could be fairly large, potentially containing hundreds or even thousands of elements. I don't THINK that's big enough to cause me to bump into memory issues or slow-down, but before I go about implementing it I wanted to see what other people thought. Does this idea require too much space to be viable?

Comment
Add comment · Show 2
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 Cherno · Oct 15, 2015 at 08:44 AM 0
Share

A better way would be to keep the array internal, so no actual GameObject for each grid position, but rather instances of a non-$$anonymous$$ono class that holds thre required data.

avatar image NerdClown · Oct 15, 2015 at 09:04 AM 0
Share

Arrays of objects are effectively arrays of references to objects. They'll probably be 64 bit each (http://stackoverflow.com/questions/3800882/how-big-is-an-object-reference-in-net), so even with a few thousand of them I wouldn't worry too much about the size of the array, more about the size of the objects it will reference.

Lookups in arrays are also pretty cheap. Where you might run into performance problems with your approach is if you want to start going over the elements.

2 Replies

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

Answer by guido-paglie · Oct 15, 2015 at 09:45 AM

Hi! This way you are talking about are made lots of games, as tetris, bomberman, etc. In one side you have the logical part, where each index represents each thing, for example in bomberman 0: indestructible block (up down left down walls) 1: grass (bomber man can move) 2: destructible block (it can be explode) 4: bomb 5: explosion (if an explosion goes to a cell that there is a index == 2, you can destroy the content ;)

in a similar way tetris is done, 0 for the cells without blocks, 1 with so if you add a block, and then you check all the 2d array and you have one line all complete of 1, you can do what tetris does... eliminate the graphics of the line ( in the logical part you will put al 0, you will push down all the lines above that destroyed line, etc..)

BUT, this have 2d arrays very small, tetris might be 7 * 25, and bomberman 30*30. But you are asking for something max of 1000*1000. Question: the map is going to be that big?? because maybe you can divide it into scenes, or you can have only rendered the 2d cell inside this big 2d cell, that the camera is seeing, i mean the portion that the camera is seeing OR only travelling the part of the 2d cell that the camera is seeing, or where the player or stuff is happening.

Anyway, 1000*1000 is too big, give it a try (better no...), 2 for i < 1000, j < 1000. and surely unity is going to crash :$. if you have i < 100, and j < 100, it does take some few seconds, so i thing you will have to think in a walk around.

hope it helps, cheers!

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 sandeepsmartest · Oct 15, 2015 at 05:36 AM

Yes,very large array of game objects will definitely effect your game performance.There will be a situation where you need to check the objects in the array very frequently or atleast 3 or 4 times for a single session , this makes the game performance very low coz you can check the array using for-loop which loops the array in every index. It is fine if you just place the gameobjects in array.If you once start checking or do some operations on the array will definitely cause performance issues. You may get exceptions like null reference if you destroy the gameobject that belongs to array.it would be bit tough to handle these kind of issues. Hope this may help you. Nsks

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

8 People are following this question.

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

Related Questions

JavaScript 3 Arrays questions 1 Answer

Array of Arrays of GameObjects/Prefabs (C#) 1 Answer

Is it possible to store variables in arrays? 1 Answer

Destroy created children of objects 1 Answer

How could I collect all gameobject Materials? 1 Answer


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