- Home /
Many UI Elements - Bad GraphicsRaycaster performance?
Hi,
in my scene i have a complex ui with a few hundrets elements (Text, Button, Images..). Of course they aren't active at the same time. They are all childs of a parent Canvas gameobject (screenshot in attachment).
Now I have the problem, that the Graphic Raycaster(it's the only one in the whole scene) has a really bad performance. The performance is bad too, when all ui objects are deactivated.
It seems thats because of having so much UI elements in the scene. It doesnt makes a difference if i activate or enable the ui gameobjects. Only when I delete them, the Calls number goes down.
So is this a bug or what can I do?
Thanks for each answer!
Answer by vicilux · Mar 07, 2016 at 01:15 PM
I also met this problem about a month ago.
this is my thing, I have a huge big canvas, you can see the raycast is crazy. 33523 times called. WHY? BECAUSE unity graphicRaycaster check every single child object when I move my mouse, regardless of it's status active/inactive.
I have many inactive objects which cause very poor performance.
Here's the solution: Never add Graphic raycaster to a root canvas which contains many inactive objects. Do use different canvases, when you deactivate the canvas, the attached raycaster won't run. I used this method and everything is working ok.
You don't have to change the hierarchy too much, just remove the raycaster component on the root canvas, add raycaster to child ui, it will automatically add canvas component.
Another thing*, remember to uncheck the "Raycast Target" attribute* of images or text if they are just for display. Otherwise it will also effect performance.
After doing all these things, It dropped from 33k to a few hundreds which is so pleasant. Good luck.
Deactivate children objs just won't tell the raycaster to skip them. You need to add more canvas, deactivate the canvas to stop the GraphicRaycast script from running!