scene with large number of objects

I’m trying to show something like 50k spheres (not that they are visible all at once) and it’s unbearably slow after about 10k. Actually after very long initialization time rendering is more or less bearable, but initialization is very very slow. I use simple colored spheres, and of course when I add something then initialization time is longer.

Is there any hope to do that faster?

I have a few questions and comments, too. :slight_smile:

  1. Why would you like to display 50k
    spheres?

  2. Is it for a debugging situation,
    i.e. you’re using them to simply
    mark some point in space? If so, use cubes instead. They consist of simpler geometry than spheres do.

  3. Are you trying to render something
    that you really should use a
    particle system for? This is stuff like running water, plumes of fire or smoke, etc. You’ll find that particles are much, much faster.

  4. If for some reason you really do need 50k spheres, must they all be instantiated at the same time? If you’re not going to be looking at them all simultaneously anyway, could you get away with instantiating them in batches? One suggestion might be to split your scene up into an octree, and then instantiate/destroy spheres based on the octree nodes that are currently present in your camera’s viewing frustrum.

In the script that is attached to the sphere, have something like:

var camera : Transform;

function Update(){

if(Vector3.Distance(transform.position, camera.position) > 1000 ){

Destory(gameObject);

}

That would destrory the sphere if it is more then 1000 units away from your camera (i have not tested this script, i just wrote it, so no guarantees it will work, but it should :D…)

Then in the “spawner” script, attach this:

    var sphere : Transform;

function Update(){

    for (var i : int = 0;i < 10; i++) {
    Instantiate (sphere, Vector3(i * 2.0, 0, 0), Quaternion.identity);
    }
    }

That would spawn 10 spheres two units apart. You can change the values though…

Remember to make the sphere a prefab though, and drag that into the “Sphere” variable in the inspector…

Try this link: http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html

Hope this helps

-Grady