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 bpears · Jan 01, 2014 at 02:16 AM · materialsubmesh

Assign new material to submesh?

If I have a object with several submeshes, and all those submeshes are using the same material, how can I pick out a specific submesh and set its material to something else? I guess im mostly confused how you would be able to find the submeshes. If the submeshes used different materials I could simply get array of materials and change the one I want. But I cant do that in this case because the material is the same for all submeshes.

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 Eric5h5 · Jan 01, 2014 at 02:22 AM

 var allMaterials = renderer.materials;
 allMaterials[numberToChangeHere] = someMaterial;
 renderer.materials = allMaterials;
Comment
Add comment · Show 11 · 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 bpears · Jan 01, 2014 at 02:25 AM 0
Share

As I said, this method wont work in this case because I want to assign a new material to only one if the submeshes. This would change it for all submeshes, because theyre using the same material at start.

avatar image Eric5h5 · Jan 01, 2014 at 02:32 AM 1
Share

No...I understood your question. It won't change it for all submeshes, only the one you pick. Each entry in the array corresponds to a submesh.

avatar image bpears · Jan 01, 2014 at 02:35 AM 0
Share

So that var creates an array of materials even if some are the same?

avatar image Eric5h5 · Jan 01, 2014 at 08:28 AM 1
Share

I'm not sure you actually are talking about submeshes. Either that or you're not using an instance of the material, because if you change a material (not an instance) then naturally everything that uses that material will change.

avatar image Eric5h5 · Jan 01, 2014 at 09:11 AM 1
Share

Every object is a separate draw call regardless of sharing a material, unless you use dynamic or static batching. Although I don't know if objects with submeshes batch (I would guess not).

Show more comments

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

19 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

Related Questions

Do submeshes get sorted properly for transparent materials? 0 Answers

How can I ensure Unity does not rearrange the sub-mesh order of a mesh from Maya?,How can I ensure Unity does not rearrange sub-mesh order of a mesh? 0 Answers

How does submesh index map to material? 1 Answer

How to work with submeshes in editor 1 Answer

Combining blender submeshes 3 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