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 ProGrahamCracker · Feb 02, 2014 at 06:19 PM · objectunity 2ddestroytiles

Do I need to destroy objects I'm not using?

I am making a 2d birds eye view exploration game. (i am new to unity btw) For now my world is a fixed size, and i am using tiles to build the land. the size is 2000x2000 tiles, a big square. each tile is an object and the camera can only see about 25 tiles at a time. so to my question. should I, do I need to destroy the tiles that are far away from my camera and recreate them when the camera is close enough? I ask because I am not sure what Unity will do for me in this case. all tips, help, suggestions, and council is welcome 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

4 Replies

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

Answer by scipiothegreat · Feb 04, 2014 at 01:25 AM

Have you considered object pooling? Instead of completely destroying a tile and making a whole new one, you could take an old, and change it to whatever new tile you need. This means you have to make your tile objects changable at runtime, but will keep you from instantiating so many tiles. Just make a class that holds references to tiles that are no longer needed and gives them out when requested.

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 Klarax · Feb 03, 2014 at 11:13 AM

I think this varies. If its the same model/sprite or whatever, the item should batch so its not a big deal.

I would leave it as it is now, and keep an eye on stats when game is running, if fps drops, then maybe look into it

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 ProGrahamCracker · Feb 03, 2014 at 09:22 PM 0
Share

I have 6 different tiles that the world can be made up from, plus having objects like trees and animals in the world. it would not be a problem for me as far as being capable to create the objects needed as i get close to them each time, but i was not sure as far as the toll it might be on the game or if creating and destroying is not intense. ill looking to some tests as you suggest. Im still curious on weather or not creating and destroying is expensive. thanks ill update and I find more out

avatar image
0

Answer by Fabkins · Feb 03, 2014 at 10:19 PM

I think you need to consider a different approach to the overall problem.

Sound like you need to use Terrains.

http://docs.unity3d.com/Documentation/Components/script-Terrain.html

Comment
Add comment · Show 7 · 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 ProGrahamCracker · Feb 03, 2014 at 10:40 PM 0
Share

This is interesting. $$anonymous$$y initial plan was to make this all 2d with sprites, but I can see how this would help build a world in 3d. ill look at this more and see if it might be worth switching to 3d. is there something similar to this for 2d worlds?

avatar image Fabkins · Feb 03, 2014 at 10:48 PM 0
Share

Well another approach is to create a mesh by hand. This actually what I've done on one project. Problem is 2000x2000 tile map is going to many vertices. The limit is 65k and that size of map would require 4 million of them (if you not re-using vertices). (just tried it and it broke :) )

avatar image Fabkins · Feb 03, 2014 at 10:50 PM 0
Share

ps , when I originally made my map I used object. $$anonymous$$y map was only 100x100 objects and it took a while to initialise. You are going to try to create x400 times that many objects, I think Unity will grind to a halt , its going to work at all.

avatar image Fabkins · Feb 03, 2014 at 10:56 PM 0
Share

Yep, it broke big style. It swallowed 4GB of memory and crashed Unity.

avatar image ProGrahamCracker · Feb 03, 2014 at 11:18 PM 0
Share

yeah i made a for loop to create that many and didnt want to finish waiting for it to load. so I am thinking that I will have about 1000 of them created and create more as I get closer to the edges and destroy the ones out side a given radius. right now I am keeping the definition of a tile in an int and I am using byte masks to read the bits (as far as what type of land, if it can be walked through, or any other items on the tile) so the bottleneck is rendering the tiles and not having that large of a world. - do you think that creating 50 tiles every 2 seconds (2 seconds for walking speed across tiles) will be taxing if I'm also destroying that many each time?

Show more comments
avatar image
0

Answer by ProGrahamCracker · Feb 04, 2014 at 09:21 PM

OK! after running some tests and doing performance and system load testing, object pooling is the way to go. create and destroy are very expensive when compared to just reusing objects. I was looking for quick and dirty at first but object pooling is easy and sophisticated. Not to mention that my first language was C, so I naturally care about memory and its allocation. Thanks a lot to all of you that helped.

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

21 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 avatar image avatar image avatar image avatar image

Related Questions

Destroy all objects in the scene? 0 Answers

How to prevent objects instantiating between scenes? 4 Answers

Destroy GameObject behind the Main Camera 2 Answers

C#: Changing current position of an object in y. 1 Answer

Game Object Not Working Properly 0 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