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 Giobar97 · Jan 11, 2015 at 05:45 PM · gameobjectinstantiaterandomseed

Best way to instantiate lots of objects

Hi, I have a script which at the start of the level instantiates lots of cubes... I'm talking of about 15k cubes at once. Obviously the loading is pretty slow, it takes about 1 or 2 minutes. I would like to know if someone can recommend some better way to instantiate all these objects. Actually, I don't think there are any other methods, since the objects should be instantiated anyway. However, asking shouldn't be a problem , and I could learn something new... So, this is how my script proceeds:

  1. The script checks if player added a seed composed of six alphanumeric characters. If not, it's generated randomly.

  2. Every character of the seed is turned into an integer relying on a sort of list (for example, a = 0; b = 1; c = 3; 1 = 0; and so on...). At the end every integer is stored in a variable.

  3. The script instantiates the first cube at position (0, 0, 0), which is the starting position of the player. After that, is starts generating cubes with the aid of some calculations which calculate x, y, and z of every cube. I will put at the end of this topic a piece of script to make this point more understandable.

  4. After that, all the cubes are made children of an empty object called "Galaxy1".

  5. Points 3 and 4 are repeated twice again, interchanging seeds, naming the groups "Galaxy2" and "Galaxy3", rotating and moving the whole groups so that you get a tangle.

  6. Finally, the script checks if there are cubes with same position, and destroys all cubes at same positions except one, so that there are no straddling cubes. In this way I delete useless cubes and avoid graphical glitches.

There's the piece of script which I talked about in point 3.

 nmcube = nmcube + 1;
         if (s6 == 1 || s6 == 4){
             x = x + 1;
         }
         else if (s6 == 2 || s6 == 5){
             x = x + 2;
         }
         else if (s6 == 3 || s6 == 6){
             x = x - 1;
         }
         if (s2 + s4 > 10)
         {
             z = z + 1;
         }
         else if (s2 + s4 < 5)
         {
             z = z - 1;
         }
         if (s6 - s2 < 4)
         {
             fattore = fattore + (s3 / s5) + 1;
             if (fattore == 1 || fattore == 3 || fattore == 4 || fattore == 10 || fattore == 12 || fattore == 13 || fattore == 14 || fattore == 20 || fattore == 22 || fattore == 25 || fattore == 26 || fattore == 30 || fattore == 32 || fattore == 35 || fattore == 37 || fattore == 40 || fattore == 43 || fattore == 45 || fattore == 46 || fattore == 50 || fattore == 58 || fattore == 59 || fattore == 60 || fattore == 70 || fattore == 71 || fattore == 72 || fattore == 73 || fattore == 74 || fattore == 75 || fattore == 76 || fattore == 77 || fattore == 78 || fattore == 79 || fattore == 83 || fattore == 87 || fattore == 88 || fattore == 89 || fattore == 90 || fattore == 100 || fattore == 101 || fattore == 102 || fattore == 104 || fattore == 131 || fattore == 134 || fattore == 138 || fattore == 145 || fattore > 150)
             {
                 y = 1;
             }
             else 
             {
                 y = 0;
             }
         }
         else
         {
             fattore = (s3 / s5) + 1;
             if (fattore == 1 || fattore == 3 || fattore == 4 || fattore == 10 || fattore == 12 || fattore == 13 || fattore == 14 || fattore == 20 || fattore == 22 || fattore == 25 || fattore == 26 || fattore == 30 || fattore == 32 || fattore == 35 || fattore == 37 || fattore == 40 || fattore == 43 || fattore == 45 || fattore == 46 || fattore == 50 || fattore == 58 || fattore == 59 || fattore == 60 || fattore == 70 || fattore == 71 || fattore == 72 || fattore == 73 || fattore == 74 || fattore == 75 || fattore == 76 || fattore == 77 || fattore == 78 || fattore == 79 || fattore == 83 || fattore == 87 || fattore == 88 || fattore == 89 || fattore == 90 || fattore == 100 || fattore == 101 || fattore == 102 || fattore == 104 || fattore == 131 || fattore == 134 || fattore == 138 || fattore == 145 || fattore > 150)
             {
                 y = 0;
             }
             else
             {
                 y = 1;
             }
         }
         tempo = GameObject.Instantiate (cube[Random.Range (0, 5)], new Vector3(x, y, z), Quaternion.identity) as GameObject;
         tempo.transform.parent = groupa.transform;
         tempo.name = "Cube" + nmcube.ToString();
         if (s6 == 3 || s6 == 6)
         {
             if (x > -31) {goto Labelone;}
             else {goto Labeltwo;}
         }
         else 
         {
             if (x < 31) {goto Labelone;}
             else 
             {
                 x = 0 - x;
                 z = 0;
                 y = 0;
                 fattore = 0;
                 goto Labeltwo;
             }
         }
     Labeltwo:

The variables "s1", "s2", "s3", "s4", "s5" and "s6" are the integers which I talked about above, at point 2.

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 GameVortex · Jan 11, 2015 at 05:48 PM 0
Share

I recommend you read up on the concept of Voxels, and search around for Unity $$anonymous$$inecraft, as there are many people that have attempted to create something similar in Unity.

This was the first thing that popped up: http://in2gpu.com/2014/07/27/build-$$anonymous$$ecraft-unity-part-1/

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Anyone know why this isn't working? 1 Answer

C# GameObjects Instantiate Into Each Other Issue 1 Answer

Three Spots For Three Random Objects 1 Answer

How to randomly spawn three non repeating gameobjects from an array? 2 Answers

Instantiate a GameObject at the position of one of its child objects 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