x


large number of identical objects in scene?

Hi there,

I am making a racing game which has a large number of fence sections to be applied at different rotations and positions along the track. I found some performance issues when all the fences were placed along the track - approximately 2k fence mesh assets. I have looked at solutions such as billboarding etc however I am unsure of what would be the best option in this case? No colliders are needed the fences are static and all have an identical texture.

Any advice would be appreciated!

more ▼

asked Jun 14 '12 at 10:42 AM

jmccnz gravatar image

jmccnz
19 3 4 4

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

This sounds like a job for CombineChildren.cs from the StandardAssets:

Attach your fence objects to one parent (they still can have individual hierarchies), and attach the script to that parent. It will optimize the meshes for rendering, reducing the number of draw calls to one, if they all use the same material.

There is a catch, that the sum of all vertices must not exceed 65000 (it will print an error in the Console if it does, and not render the objects). If this happens, simply distribute your fences over several parent objects with the script attached to each.

more ▼

answered Jun 14 '12 at 10:53 AM

Wolfram gravatar image

Wolfram
9.1k 8 20 53

(comments are locked)
10|3000 characters needed characters left

I think your bottleneck is the number of drawcalls caused by having 2k+ fences. In your situation, where the fences are static and do not move relative to each other, it's possible to consolidate the drawcalls by combining the fences into a single mesh using Mesh.CombineMeshes. This causes Unity to batch them all into a single mesh so you can "bulk draw" them, so to speak.

Beware that this has the disadvantage that the combined length of the fence mesh will evaluate to visible for all fence segments, since I assume some smaller portion of it will always be within the camera's view frustum. This means frustum culling becomes less efficient as the engine must spend time rendering polygons of a larger mesh that aren't in the scene, because a few polygons of the combined mesh are. But it might still be better than 1 draw call per fence segment.

Perhaps you can come up with some hybrid solution where you use Mesh.CombineMeshes on many fence segments (but not all), so you combine stretches of, say, 100 fence meshes into 1 mesh? Then you'll reduce your 2k fence prefabs to 20 meshes, the origin of each is 100 fence prefabs, position one after another along your track.

A completely alternative solution which doesn't involve Mesh.CombineMeshes might be to dynamically instantiate/destroy fence prefabs based on what portion of the track the camera is currently viewing, so, when the car drives forward, past fences get destroyed and fences just ahead of the camera get instantiated.

more ▼

answered Jun 14 '12 at 10:55 AM

CHPedersen gravatar image

CHPedersen
6k 13 22 62

(comments are locked)
10|3000 characters needed characters left

If you can't see all the fences at one time, maybe moving the fences along with the camera (you'll have to work out some way of snapping the fences to the correct positions as the camera moves) then you could reduce the number of fence items in the scene at any one time.

more ▼

answered Jun 14 '12 at 11:43 AM

zz74b gravatar image

zz74b
98 2 3 5

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3891
x2172
x744
x678

asked: Jun 14 '12 at 10:42 AM

Seen: 573 times

Last Updated: Jun 14 '12 at 11:43 AM