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
0
Question by pauloapsantos96 · Oct 16, 2014 at 04:14 PM · c#texturematerialsbatchinginstances

Material Instances Problem.

I'm having a problem with a GameObject that contains 2 materials. I'm doing the following:

 renderer.sharedMaterials[ 1 ] = Resources.Load( materialPath ) as Material;
 renderer.materials[ 0 ].mainTexture = Resources.Load( texturePath ) as Texture;

So i'm trying to change the 2nd material in all GameObjects but keeping it batched. This works until i change the 1st material's mainTexture to a different one in each GameObject, after doing this the 2nd material becomes an Instance.

I would like to know if its possible to have one of the materials batch and the other be an instance. Thank's in advance.

Comment
Add comment · Show 1
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 MrSoad · Oct 17, 2014 at 11:20 PM 0
Share

If you store a $$anonymous$$aterial in a var, then set this material(var) to multiple objects at run time, then they will batch as if you had manually set the texture to them all in the editor. This may still give you one extra DC but maybe it could help you...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Oct 17, 2014 at 11:13 PM

If you change any property of a material at runtime...and that includes changing any material in the materials array...you get a new material instance. The typical solution to this problem is to use a texture atlas. That way you can have multiple textures combined in to a single texture and therefore use a single material to present multiple different (and differently textured) objects.

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 pauloapsantos96 · Oct 18, 2014 at 09:33 PM 0
Share

Well but my problem is that one of the 2 materials in the array is the same in all objects and the other is different in all objects. But both of them are marked as instances. Sorry if you answered this already but i didn't understand fully.

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

29 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

Related Questions

Multiple Cars not working 1 Answer

Having a problem with the second material (on the same renderer) 0 Answers

Distribute terrain in zones 3 Answers

Is it bad to have this many materials? 2 Answers

How do I attach a Created Material A Texture, NormalMap and OcclussionMap? 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