x


Meshes as Variables...

If I assign a mesh in the editor to a public variable in script of type "Mesh", when I assign it's content to an object (...meshFilter.mesh = ...), does Unity LOAD the Mesh then, or is it already cached in memory?

I change meshes on a number of my objects over the course of the game, and I'm noticing quite a bit of slowdown, even on iPhone 3GS. This shouldn't be the case, as there are only around 20 objects, and they're all box colliders?

Anyone have any ideas?

more ▼

asked Jan 13 '10 at 05:14 PM

S7ARBVCK gravatar image

S7ARBVCK
80 6 8 8

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

4 answers: sort voted first

Why not attach all the various meshes to a parent gameObject, and simply turn on or off the ones you need or don't need?

more ▼

answered Jan 26 '10 at 05:29 AM

Brian Kehrer gravatar image

Brian Kehrer
2.8k 9 11 50

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

When you assign the mesh, it gets loaded into the graphics hardware. I think that is what slows things down.

more ▼

answered Jan 13 '10 at 08:47 PM

andeeee gravatar image

andeeee ♦
1.4k 3 6 18

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

Any way to get around this, then? Any way to "pre-load" meshes so I don't get the performance hit?

more ▼

answered Jan 15 '10 at 12:45 PM

S7ARBVCK gravatar image

S7ARBVCK
80 6 8 8

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

Can you use prefabs? The performance will be far greater if you are using prefabs.

more ▼

answered Jan 26 '10 at 05:10 AM

thom gravatar image

thom
119 2 4 9

Prefabs have no effect on performance. They exist primarily for convenience and workflow reasons; for example a cube placed manually and a cube instantiated as a prefab are identical in the actual scene.

Jan 26 '10 at 11:50 AM Eric5h5

I was under the impression that prefabs use shared meshes and shared materials so performance would be improved. Certainly the tutorials I learned on stressed creation of prefabs for performance but thanks for the heads up--I learn something every day!

Jan 26 '10 at 06:36 PM thom
(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:

x1667
x1352
x816

asked: Jan 13 '10 at 05:14 PM

Seen: 1072 times

Last Updated: Jan 13 '10 at 05:14 PM