2D Toolkit Forum

2D Toolkit => Support => Topic started by: wagenheimer on October 10, 2014, 03:52:47 am

Title: Changing Color is Slow
Post by: wagenheimer 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!

Title: Re: Changing Color is Slow
Post by: unikronsoftware 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...
Title: Re: Changing Color is Slow
Post by: kevindqc 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 :)