Massive arrays, masses of low-poly objects

I’m thinking about building a scene on the fly in a “Lego” kind of a way, from prefabs. Basically like flying through a city where every building is a random stack of several blocks.

I’m thinking big: like 1000 buildings with around 6 prefabs each. They’d be simple: 50 to 500 polys, average 200 polys. Maybe 50 to 100 prefabs in the “library” that gets drawn from, and multiple different textures being randomly selected too. And each prefab would be a mesh collider as well.

So is 6000 instances/colliders, with an assortment of textures just asking for trouble?

Three things that help:

  1. The prefabs would never move once they’ve been placed.

  2. They would NOT all be VISIBLE at once: I intend to arrange things so that your view is constrained to maybe 5-15 buildings at once. (In other words no long open streets to look down.) About a million polys total, BUT only 10 to 20,000 in view at once.

  3. I’m not targeting low-end machines. (This is a playground for something I’d like to do “someday,” nothing I’ll finish soon.)

Along with the prefabs, my script for laying out the “city” and controlling enemies within it would need a large array. I’m thinking maybe a 10x10x10 array, and each element IN the array would be ANOTHER 10x10x10 array. (Can you nest arrays like that in Unity without manually declaring every one?)

That’s a million data points. Anything I should be warned of re arrays of that complexity? (I know there would be a delay as the data is fed INTO the array, but it would only happen once–the data would not change mid-game, it would just be there for the enemies to “look up” tactics in.)

Thanks in advance!

Basically having 6000 objects is not a very good idea. What you really want to do is combine your objects on the fly into larger combined objects that have at least 1500-2000 triangles each.

Using the mesh interface you can easily combine objects. I’ll also post a script that combines all meshes that are transform children at startup soon.

That would be fantastic…I was just about to ask a similar question, actually.

(“Unity support: so good, we reply before you even ask.” :wink: )

–Eric

Great! I didn’t even think of that. Would each mesh in the “combo” retain its own unique texture?

Either it’d share a texture (just have different things have their own little spot in the UV map) or his script would have to generate multiple materials, in which your performance gains would be lost. (Each material is a rendering pass)

-Jon