2D Toolkit Forum
2D Toolkit => Support => Topic started 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 :
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!
-
You're calling it 672 times a frame. Set it in Update / LateUpdate and you'll cut it down to a third...
-
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 :)