x


Adding extra materials to a mesh programmatically

I'd like to add extra procedural geometry / materials to an authored mesh at import time. I have a custom AssetPostprocessor script that creates a new, larger, Material[] array with the additional materials appended, assigns it to renderer.sharedMaterials, sets the appropriate value to renderer.sharedMesh.subMeshCount, and performs the renderer.sharedMesh.SetTriangles() calls.

However, Unity appears to promptly discard the new materials, resetting the content of renderer.sharedMaterials to just the materials present in the fbx, by the time Start() is called on monobehaviours attached to the parent gameobject - although the submesh count remains what I set it to, and the extra geometry is still present.

Why does this happen? What is the correct way of adding extra materials to a mesh?

more ▼

asked Jun 24 '11 at 09:30 AM

toothycat gravatar image

toothycat
106 7 8 9

Everything sounds about right... Do you create new materials or do you reuse them from somewhere? Can you post your code?

Jun 24 '11 at 03:15 PM Paulius Liekis
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
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:

x1356
x299
x52
x33

asked: Jun 24 '11 at 09:30 AM

Seen: 1230 times

Last Updated: Jun 24 '11 at 03:15 PM