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 Utamaru · Mar 24, 2015 at 03:15 PM · spritematerialcolorspriterendererbatching

Change sprite's color without making an extra drawcall

I have multiple sprites (with SpriteRenderer component), and they share the same material. For assigning material I use this code:

 renderer.sharedMaterial = AppSettings.MaterialSpriteDefault;

And if I change color in SpriteRenderer, nothing changes in the scene, sprite remains the same. But if I assign material like this:

 renderer.materials [0] = AppSettings.MaterialSpriteDefault;

every sprite = extra drawcall, because Unity creates new instance of material for every sprite, and I'm trying to get rid of it. Any thoughts about how I can achieve desired behaviour?

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 hexagonius · Mar 24, 2015 at 03:22 PM 0
Share

How do you change the color? With the default sprite shader you're not getting additional drawcalls by changing tint.

avatar image Utamaru · Mar 24, 2015 at 03:29 PM 0
Share

I change color using spriteRenderer.color. If the material is shared - nothing happens in the scene, the color remains the same. If I change color to shader in shared$$anonymous$$aterial, it says "$$anonymous$$aterial doesn't have a color property '_Color' ". But if sprites have their own instance of material, shader's color is changing.

avatar image hexagonius · Mar 24, 2015 at 03:42 PM 0
Share

I did a little test, copying a sprite 15 times (16 total) with this piece of code on them

 void Start () {
         GetComponent<SpriteRenderer> ().color = new Color (Random.Range (0, 1f), Random.Range (0, 1f), Random.Range (0, 1f), 1);
     }

One drawcall, 15 batches, changed color in game view. Don't know what you did wrong, but maybe that gives you the right hint.

avatar image Utamaru · Mar 24, 2015 at 03:48 PM 0
Share

This is really strange. I did the same in test scene and everything worked. But in my current scene it won't work for some reason. http://monosnap.com/image/fiZxquH8$$anonymous$$IeHw1D$$anonymous$$ggiAzNUPxGtHXk

avatar image Utamaru · Mar 24, 2015 at 03:59 PM 0
Share

Okay, for some reason the problem probably was in adding spriteRenderer component to gameObject manually from code. I dragged sprite into the scene, Unity created gameObject with spriteRenderer for me, I made prefab from it, and used it as template for my next sprites, and now everything works fine. Really weird behaviour.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

22 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

Related Questions

How to access SpriteRenderer Color from a shader? 1 Answer

Material doesn't have a color property '_Color' 4 Answers

Changing two different objects renderer colour 1 Answer

How to get Sprite color palette 1 Answer

,Sprite Successfully Color changing in Shader Graph but not in code 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