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 KEELAN · Aug 27, 2014 at 05:22 PM · prefabdraw calls

How to change the colour of a prefab back to default to save draw call

Hi, In my game I need to change the colour of a prefab for a certain amount of time, which obviously then increases the number of draw calls, how would i change it back the the prefabs default later to then decrease the draw calls?

thanks in advance.

Comment
Add comment · Show 6
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 vptb · Aug 27, 2014 at 05:38 PM 0
Share

Why don't you save the original color on a variable before changing it? Then you can just return to the original one.

avatar image KEELAN · Aug 27, 2014 at 06:01 PM 0
Share

because that doesnt reduce the number of draw calls

avatar image rutter · Aug 27, 2014 at 06:04 PM 0
Share

You might try caching the original shared$$anonymous$$aterial, then re-using it once you're done (example). I haven't tried this, so I don't know for sure if it will still save your draw calls.

avatar image robertbu · Aug 27, 2014 at 06:08 PM 0
Share

Depending on the object, you could change the color using a shader that supports vertex colors and change the color by changing the colors array in the mesh. That way even objects with different colors will batch.

And if you try @rutter's suggestion, let us know if it works.

avatar image KEELAN · Aug 27, 2014 at 06:17 PM 0
Share

Thanks rutter , I just tried that now and it doesnt seem to help. I did notice something weird though, if you store the material of the prefab (not apply or change) then the draw calls increase too. seems very odd

Show more comments

1 Reply

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

Answer by Eric5h5 · Aug 27, 2014 at 06:25 PM

Once you've changed the color, you've created a new material instance, so just changing the color back will have no effect since you're still using the new material instance. The best thing is not to create new material instances, which will require other techniques such as vertex colors or texture atlases. (The color property for sprites, for example, uses vertex colors.)

Or, depending on what you're doing, it may be feasible to manually create one or more material instances yourself, then change the color of those instances and use sharedMaterial to assign them as needed. So you'd never use renderer.material, only renderer.sharedMaterial.

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 KEELAN · Aug 27, 2014 at 06:43 PM 0
Share
 GetComponent<SpriteRenderer>().color = new color

that did the trick. Thanks

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

24 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

Related Questions

Designing Levels in 3DS Max? 1 Answer

Display Item Sprite on Inventory UI 1 Answer

Please help with beginner Prefab & OnMouseDown 1 Answer

Add Asset Bundle Name to a prefab in "Editor Code" 1 Answer

Prefab of a prefab? 4 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