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 benjaminoutram · Nov 05, 2015 at 01:28 PM · renderingparticlesperformance optimizationprocedural mesh

Rendering 100000+ of simple objects whose colour I can control

I have created a large cubic lattice of thousands of cubes (or spheres), and I want to procedurally control their colour (so I can, for example, make it appear that a wave of colour moves through the lattice via controlling the cubes' colours). Here is the code:

 void Start () {
 
         //initialize cube field
 
         cubes = new GameObject[cubeFieldSize [0], cubeFieldSize [1], cubeFieldSize [2]];
 
         for (int i = 0; i < cubeFieldSize[0]; i++) {
             for (int j = 0; j < cubeFieldSize[1]; j++) {
                 for (int k = 0; k < cubeFieldSize[2]; k++) {
 
                     //instantiate array of objects (cubes or spheres)
                     if(preferSpheres){
                     cubes[i,j,k] = (GameObject)Instantiate (sphere, transform1.position, Quaternion.identity);
                     }
                     else{
                     cubes[i,j,k] = (GameObject)Instantiate (cube, transform1.position, Quaternion.identity);
                     }
 
                     //make children of parent
                     cubes[i,j,k].transform.parent = transform;
 
                     //set up positions of objects
                     cubes[i,j,k].transform.position = new Vector3 ((i-cubeFieldSize[0]/2+0.5f)*cubeSpacing,
                                                                    (j-cubeFieldSize[1]/2+0.5f)*cubeSpacing,
                                                                    (k-cubeFieldSize[2]/2+0.5f)*cubeSpacing);
                     //set up scale of objects
                     cubes[i,j,k].transform.localScale = new Vector3 (cubeSize,cubeSize,cubeSize);
 
                 }
             }
         }
 }

I am controlling the colour of the objects using

                             cubes[i,j,k].GetComponent<Renderer>().material.color = colours[m];
 

My problem is that I would like to render a lot of objects, but of course the larger the number the more it slows. Is there a more efficient way to render 100,000+ objects?

I thought maybe I could use a particle system, since I don't really need to draw entire meshes for my purpose, just circles or lights would do?

Or I saw one Unity Answer that talked about procedural meshes?

Any suggestion of how these might be implemented in my case, with the colours being controlled, and so I can draw many more objects than I can at the moment, would be much appreciated.

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 · Nov 05, 2015 at 02:26 PM 1
Share

Yes, if the objects don't need to move, then a procedural mesh is probably a good idea. The Unity Scripting API for the mesh class gives you the required information, and there's a sample script on the User Wiki for creating planes on the fly. All you have left to do is change the mesh colors, and use a shader that supports vertex colors.

avatar image JoeStrout · Nov 05, 2015 at 04:27 PM 0
Share

@Cherno is quite right. That should be the answer.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by TiPE_intuity · Nov 05, 2015 at 04:42 PM

As you suggest a particle system appears to be the best solution. Particles are way simpler to calculate for unity because they are missing most of the attributes gameObjects have. Additionally particles can be controlled over their system in terms of position, movement, size etc.

You could use your structure to write the positions and sizes in an array which can be handed to the particle system in the next step, for all particles at once. (Same is true for color)

One disadvantage of particles is, that they usually have no depth. You can image a particle as a flat image, which always rotates to face the camera.

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

35 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

Related Questions

Text Update demands too much performance 0 Answers

Shadow artifects on mesh with Standard shader 1 Answer

Performance with a 250x250 grid 0 Answers

Trouble with Occlusion Culling 0 Answers

Particles not rendering correctly 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