Hello Guest

Author Topic: Changing Color is Slow  (Read 2808 times)

wagenheimer

  • 2D Toolkit
  • Jr. Member
  • *
  • Posts: 50
    • View Profile
Changing Color is Slow
« on: October 10, 2014, 03:52:47 am »
I have +- 200 child sprites, and I need there sprites to match the parent sprite color.

In fixedupdate I have this :

Code: [Select]
childSprite.color = parentSprite.color;

But this seems to be very slow, please see the attached profiler screenshot.

Why is this code so slow? How can I change it to improve it?

Thanks!


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Changing Color is Slow
« Reply #1 on: October 10, 2014, 09:16:01 am »
You're calling it 672 times a frame. Set it in Update / LateUpdate and you'll cut it down to a third...

kevindqc

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Changing Color is Slow
« Reply #2 on: October 10, 2014, 03:11:37 pm »
AFAIK, updating the color needs to update the vertices color. So it needs to do that for 200*4 vertices. :(

Maybe you could create a new shader with a "color" parameter, and in the fragment shader, instead of using the vertices color, use that instead. Have the children have the same material, and just call SetColor once on the material ?

Correct me if I'm wrong, I'm pretty new with 2d toolkit/unity :)