Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
4
Question by pickledzebra · Apr 12, 2010 at 01:02 PM · materialimportasset

How NOT to create redundant materials with new names on import?

Let's say I have an asset A that contains materials X,Y,Z.

I have another asset B that also contains materials X,Y,Z.

I would like to import A and then import B and create only materials X,Y,Z in unity3D. Instead, I am getting materials A-X A-Y A-Z B-X B-Y B-Z

Now imagine I want to import 500 assets that all use X,Y,Z. I'd really rather not have 1500 materials when I only need 3.

Thanks for any tips or pointers!

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

2 Replies

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

Answer by davebuchhofer · Apr 12, 2010 at 09:45 PM

I have a postprocessor that does just that: http://buchhofer.com/?p=228 adjust your paths to suit, and also your default shader type.

//file: MaterialsPostProcessor.cs //goal: Share a library of materials across different assets //based on the name of material supplied in the FBX file //Dave Buchhofer - 02.10.2010

using UnityEngine; using UnityEditor; using System.Collections;

public class MaterialsPostProcessor : AssetPostprocessor { Material OnAssignMaterialModel (Material material, Renderer renderer) { //The path where you keep your "Standard" library of materials string StandardMatPath = "Assets/DMGStandardMaterials/" + material.name + ".mat";

     //the path where you want to keep your "temp" materials, that weren't found above
     //So you have a logical place to look for materials that need editing and tweaking for realtime work.
     string TemporaryMatPath = "Assets/Mesh/Materials/" + material.name + ".mat";

     //Check for it in the standard 
     if (AssetDatabase.LoadAssetAtPath(StandardMatPath, typeof(Material)))
     {
         Debug.Log("FOUND: " + StandardMatPath);
         return (Material)AssetDatabase.LoadAssetAtPath(StandardMatPath, typeof(Material));
     }
     //Else check to see if we've already built one in the temp path
     if (AssetDatabase.LoadAssetAtPath(TemporaryMatPath, typeof(Material)))
     {
         Debug.Log("FOUND temp: " + TemporaryMatPath);
         return (Material)AssetDatabase.LoadAssetAtPath(TemporaryMatPath, typeof(Material));
     }
     //Or create it?
     material.shader = Shader.Find("Diffuse");
     AssetDatabase.CreateAsset(material, TemporaryMatPath);
     Debug.Log("CREATED temp: " + TemporaryMatPath);
     return material;
 }

}

Comment
Add comment · Show 1 · 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 pickledzebra · Apr 12, 2010 at 11:37 PM 0
Share

Thanks so much. I'll try these approaches.

avatar image
1

Answer by alexnode · Apr 12, 2010 at 03:03 PM

You have to create a script for the assetPostprocessor to say that I want unity to assign these materials. Here is an example tool that creates colliders only for the objects containing the word collider in them. The logic is the same, consider using user properties in your objects (Max,Maya) for more detailed control concerning materials.

Have a look at this answer too. here

I am still struggling to create a proper pipeline, but if you are more adept in coding it seems fairly easy to do whatever you want just by naming objects in your 3d app.

Comment
Add comment · Show 1 · 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 pickledzebra · Apr 12, 2010 at 11:40 PM 0
Share

Thanks for the pointers. $$anonymous$$y pipeline is goofy - I have very little if any control over the user properties of the objects I'm importing. I'll give the postprocessor scripting a try.

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

Material tiling on imported fbx model doesn`t fit 0 Answers

Import Blender Model - Assigning Materials 3 Answers

Importing Maya assets with applied textures shown 0 Answers

Imported Materials Are Null 0 Answers

Creating a Material from shader string 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