Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Moritz · Sep 28, 2010 at 01:06 PM · meshmaterialmultipledefault

Default materials on meshes

Hello,

I'm really surprised that nobody asked that yet (or at least I didn't find it), but I have a question regarding the default material of a mesh when it's spawned in a scene:

How can I apply a default material to multiple meshes? The only way I know to apply a default material at all is naming it [mesh_name]-defaultmat, which is obviously not usable for materials that can be used for more than one mesh.

Thanks in advance,

Moritz

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by skovacs1 · Sep 29, 2010 at 10:17 PM

From your description, I'm pretty sure you're referring to the materials generated on import of an object when material generation is turned on. When an object is "spawned in a scene", it uses the materials assigned to the prefab. You could change the materials after the import, but it's easier in my opinion to simply fix the problem before it starts.

I wanted to assign my own materials to my geo on import for some of my mats so that they use the same mat shared across multiple models. I created an editor script which would assign stored material assets in stead of generated ones, using the names of the materials as a basis.

//Goes in the Assets/Editor folder class MaterialOverrideProcessor extends AssetPostprocessor { var materialsPath : String = "Materials";

 function OnAssignMaterialModel(material : Material,
                                renderer : Renderer) : Material {
     var materialPath : String = "Assets/" + materialsPath + "/"
                                 + material.name + ".mat";
     return AssetDatabase.LoadAssetAtPath(materialPath, Material);
 }

}

If you wanted to do something special for materials whose names contain default, you could just add some string comparison to look for that:

//Goes in the Assets/Editor folder class MaterialOverrideProcessor extends AssetPostprocessor { var materialsPath : String = "Materials";

 function OnAssignMaterialModel(material : Material,
                                renderer : Renderer) : Material {
     var materialName : String = material.name;
     if(materialName.Contains("default")) materialName = "default";
     var materialPath : String = "Assets/" + materialsPath + "/"
                                 + materialName + ".mat";
     return AssetDatabase.LoadAssetAtPath(materialPath, Material);
 }

}

If LoadAssetAtPath cannot find the material, it will return null. If OnAssignMaterialModel returns null, then the default material generation will be used. If you wanted to create a new mat or something, you could create that mat and then return the created mat like they do in the OnAssignMaterialModel docs.

If you've already imported your objects and put them into the scene and lost their prefab links, you could always write a scriptableObject script that will recurse through your asset and replace the mats.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Moritz · Sep 30, 2010 at 04:29 PM 0
Share

Thanks, I'll try it out. :)

avatar image Moritz · Oct 04, 2010 at 04:15 PM 0
Share

$$anonymous$$ight take a while until I'm able to, as Unity 3 doesn't work on my PC. :/

avatar image skovacs1 · Oct 04, 2010 at 04:38 PM 0
Share

No worries. Just post back once you're up.

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How to apply a texture to a submesh 1 Answer

Animal Crossing - Technical Question 1 Answer

How can I overlay an image across multiple game objects? 1 Answer

Character lighting issues 0 Answers

Combine meshes with different materials 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges