- Home /
Alternative to LineRenderer/TrailRenderer
Hello,
I'm trying to make some lasershots/projectiles for a top downshooter and I've found LineRenderer to be pretty nice for lasers/laser shots, however each LineRenderer will cause a drawcall, which is deadly in a top down shooter with high number of shots on the scene, so this will definitely kill performance on Smartphones.
So I need some replacement to the LineRenderer which will allow dynamical batching? Or a wait to make the LineRenderer work with dynamic batching.
I setup a multi laser shot (5 shots at once) but it's causing 5 draw calls, even though they all use the same material. Any ideas?
Regards Tseng
'A' drawcall? Out of thousands? Well, you could always write your own line renderer that works in a similar way, but with systems to make sure you only use one mesh per material...
Yea well... if you run a Unity Game on a smartphone, you have to $$anonymous$$imize the draw calls drastically! In my other game I increased performance by around 100% by reducing the draw calls from ~90-120-ish to less than 40. With 120 draw calls I had around 20 fps. Now the game runs with 40-50 fps.
I just did the error to first build and test it as a webplayer, everything was working fine there because PC had powerful CPU and GPU, but on a Smartphone its different. It took me like 4 weeks to change half of the game assets to dynamically batch which was great performance boost on Smartphones.
So I see this beco$$anonymous$$g a problem, if I have my space ship shooting 5 lasers at once and doing like 10-15 shots (on "autofire), that quickly sums up to 50+ calls only for the lasers not even considering the other enemies, their shots and environment
Well, that's pretty serious. I would recommend using just mesh renderers and coding them so they stretch like a line renderer would! If your game is top-down only, you don't even have to worry about facing the camera.
I'm running into a similar problem, did you ever find a solution Tseng?
No, not really. I just went and made the laser projectiles as sprites and use 2D Toolkit to generate the atlas for it. However, this doesn't solve the trail problem
Answer by ErikKalkoken · Dec 15, 2014 at 11:20 AM
The performance of the LineRenderer is terrible. I have about 15.000 lines in my oculus rift app that are generated by script and it was impossible to keep the needed 75 FPS. But I found a better solution and now create them by myself with meshes and its lightning fast.
See this link to a great article to learn how it works: 3 ways to draw 3D lines in Unity3D
Two remarks to the article:
In spite of what the article saysyou can indeed use the graphics class with unity free (Tested with 4.6)
Instead of using DrawMesh calls in Update() I attached the meshes to game objects instead (with MeshFilter). That gives you more flexibility and seams to be just as fast.
Hope this helps.