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
0
Question by No_Username_Found · Nov 16, 2018 at 07:49 PM · materialsrendererobj

OBJ model can only have instance materials?

I have a simple code that changes the material of an object to a material from an array.

             public Material[] allMats;           //an array of materials
             public Transform cubePrefab;  //a model with at least 1 child transform
 
 void Start(){
             Transform t = Instantiate(cubePrefab, transform.position, Quaternion.identity, transform);
             t.name = "TEST";
             t = t.GetChild(0);
             t.GetComponent<Renderer>().sharedMaterial = allMats[0];
 }

However, this code will give two different results depending on whether I use the default Unity Cube, or my own OBJ model from blender. The OBJ is just a quad.

My OBJ will always get assigned an (instance) of the material, and the Unity cube will always get a non instance. I want my custom quad to get a non instance material.

What causes this? What model properties interfere with Unity materials? Is it OBJ format specific?

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
2
Best Answer

Answer by Happeloy · Nov 16, 2018 at 08:06 PM

I can't test this myself right now, but it could be worth trying. If you select the obj-file in the project view, you should see some info in the inspector. If you press the tab "Materials", there should be two buttons, "Extract Textures" and "Extract Materials". Try pressing those. You can also select on the dropdown menu if you want to use the embedded materials, or external materials.

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 Tomer-Barkan · Nov 16, 2018 at 08:23 PM 1
Share

I believe this is the answer. By default there's the "Embedded $$anonymous$$aterial" in the obj file, and I believe you can't change that one, hence it will create an instance. If you extract, or change it to the legacy "Use external materials", it will have a separate material from the obj file, one you can modify from code using shared$$anonymous$$aterial. Give it a try.

avatar image No_Username_Found · Nov 16, 2018 at 10:53 PM 0
Share

I also had to go back through my prefabs and rebuild a few of them. When I adjusted my imported OBJ, the change worked for new instances of the OBJ but did not automatically affect my prefab objects that used the OBJ.

avatar image No_Username_Found No_Username_Found · Nov 17, 2018 at 12:40 AM 0
Share

...which also means that if the instance of the OBJ that is imported is modified in any way, such as adjusting the hierarchy of children in the instance, it breaks the relationship with the imported OBJ and thus looses the import settings. :: For Clarity :: 1) Import OBJ to project. 2) $$anonymous$$odify import settings to allow external materials. 3) Instantiate object into scene (everything works properly). 4) Expand model to view children, delete a child. 5) OBJ no longer references the import settings (because child was deleted), and will now only have (instance) of materials.

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

100 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Changing all materials of selection from code 0 Answers

Fuse objects visually when close to each other Shader/ Effect 2 Answers

Renderers with multiple materials 0 Answers

Index array is out of range (following H&S tut) 2 Answers

Swapping out a single material on a SkinnedMeshRenderer at runtime 0 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