• 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 bl4cksky · Sep 15, 2018 at 04:04 PM · multiple objectsgameobject.active

Activating/deactivating lots of gameobject at the same time

Hello everyone, i'm Gabriel

I'm currently wortking on a base building game (dwarf Fortress-like) and i have a problem with big maps. I'm not very used to unity but i did this using tutorials and so far eveything was going on quite well.

The at first i used a 16*16*16 map and everything worked well. But now that i add depth and scale (64*64*64), i am encountering some problems.

I render only one layer of my map (4096 gameobjects). Those layers are composed of cubes. One cube is a game object with a script attached, and 6 children , each of them being a quad (meshfilter+mesh renderer + a material from 32*32px texture) with a meshCollider (used for clicking on the tile). Those gameobjects are static, and all cube from a layer are attached to an empty GO.

hierarchy :

-WorldManager

------- layer_0

------------------tile_0_0_0

------------------tile_0_0_1

------------------tile_0_0_1

------------------+4093 others

------- layer_1

------------------tile_0_1_0

------------------+ 4095 others

------- + 62 other layers

etc

When i change the level, i deactivate one layer gameobject and activate another, while ckecking for tiles that could have changed, with this code :

 tileGOCS[64,64,64] : gameobjectController array
 tileGOCSparents[64] : layer array
 
         // deactivate level from
         tileGOCSparents[YlevelFrom].SetActive(false);
 
         // actiavte level we go to if it exists
         if (tileGOCSparents[YlevelTo] != null) tileGOCSparents[YlevelTo].SetActive(true);
         // else create it
         else {
             GameObject parent = new GameObject("TileLayer_" + YlevelTo);
             parent.isStatic = true;
             parent.transform.SetParent(this.transform);
             tileGOCSparents[YlevelTo] = parent;
         }
 
         // check for tile without object
         for (int x = 0; x < tileGOCs.GetLength(0); x++) {
             for (int z = 0; z < tileGOCs.GetLength(0); z++) {
                 if (tileGOCs[x, YlevelTo, z] == null) {
                     Tile t = Ref.world.GetTileAt(x, YlevelTo, z);
                     CreateTileGO(t);
                 }
             }
         }

And it takes a little less than one second to change between levels. And i would like to show at least 3 levels for depth percpetion. So my questions are : - are 4000 go too much for unity to handle? - are my gameobjects to computer-heavy? i tried removing the colliders but it changed little - i have an up-to-date computer so i don't think it's a question of hardware but optimization

Thanks in advance for yours answers. Feel free to ask me details about that.

Comment
Add comment · Show 1
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 Glurth · Sep 15, 2018 at 05:03 PM 0
Share

bug: not that it matters yet, because your map is even on all sides, but I think this zero should be a two.

 for (int z = 0; z < tileGOCs.GetLength(**2**); z++) {

Question: does it take almost a second the FIRST time you goto a level (when it must create all those gameobjects), or does it also take this long when you goto the same level a SECOND time (checks- but does not create all those gameobjects). Also, if you are not RE$$anonymous$$OVING gamobject's when you switch levels (NOT implying you SHOULD), why don't you just create them all ONCE during game initialization?

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Related Questions

Retrieve multiple items from an array of GameObjects 2 Answers

Error in running Start() when multiple instances in scene 0 Answers

Activating something on multiple objects 1 Answer

When camera switches, rigidbody.velocity doesn't work 1 Answer

OnMouseDown If-statement Question 3 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