x


Collada Import and shared materails

I'm importing a whole bunch of models that are collada. A lot of them share textures. I set the importer to look in the entire project to find materials. Nonetheless at run time it seems like all models are using instances of the materails rather then the materials themselves and that this is preventing batching.

How can I get Unity to share materials across these imported models??

more ▼

asked May 01 '12 at 01:15 AM

jeffpk gravatar image

jeffpk
16 5 5 8

I should add that there are hundreds of them. Individually setting them in the editor is otu of the question. I did try to make prefabs from them via a script-- and it crashed Unity which seemed unable to handle converting such a large number to prefabs.

May 01 '12 at 01:21 AM jeffpk

Is it posible for you to convert those models to FBX files, because I have tried to use collada before and it just doesn't work well. So try that and let me know how it goes:)

May 01 '12 at 01:58 AM Ampler Games

FBXs show exactly the same symptoms

May 01 '12 at 07:11 PM jeffpk

What program are you using to make all the models?

May 01 '12 at 11:07 PM Ampler Games
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

I'm not. They are existing data I am ripping and recoding. Im doing the collada trans-coding myself with a program I wrote.

I can modify the collada pretty freely if that would help.

more ▼

answered May 01 '12 at 11:25 PM

jeffpk gravatar image

jeffpk
16 5 5 8

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

I ended up having to force the textures to be shared at runtime. As i instance each object I submit it to this class which forces like named materials to be shared. Now dynamic batching works.

using UnityEngine;
using System.Collections.Generic;

public static class MaterialsCache  {
    static private Dictionary<string,Material> matDict = new Dictionary<string, Material>();
    public static void UsedSharedMaterials(GameObject obj){
       Renderer[] renderers = obj.GetComponentsInChildren<Renderer>();
       foreach(Renderer rend in renderers){
         Material mat = rend.material;
         if (matDict.ContainsKey(mat.name)){
          mat = matDict[mat.name];    
         } else {
          matDict[mat.name] = mat;    
         }
         rend.material=mat;
       }
    }

}
more ▼

answered May 02 '12 at 07:01 PM

jeffpk gravatar image

jeffpk
16 5 5 8

(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:

x973
x274
x115
x28

asked: May 01 '12 at 01:15 AM

Seen: 592 times

Last Updated: May 02 '12 at 07:02 PM