- Home /
Moving from Renderer to SpriteRenderer causes Lag on Mobile
Heya!
Recently I created some graphics and imported them into my mobile game. I was previously using the Renderer for my 2D graphics and simply swapping between different materials (PNG images that I uploaded into Unity). This was working really smoothly in my game. I Recently, I switched the materials to be sprites and on build the game is no longer moving smoothly. There is a lot of jittering to the visuals.
Does anyone know why switching from a Renderer to a SpriteRenderer is causing this lag? There don't appear to be any problems when running the game through the Editor either. I'm completely confused. :-/
P.S.: If any clarification is needed, please let me know. Thanks! :-)
UPDATE: I'm still having trouble figuring out exactly what is going on here, but it looks like this is not because of swapping between graphics.
When creating a level, I am reading an XML script produced by Tiled and Instantiating a "Spikes" gameobject at each location. When the next level is started, I destroy all of the objects, and read the XML for the next level (I have not implemented Object pooling yet to create my levels, but plan on it. I only found out about it recently).
What confuses me however, is that these objects do not move and do not have an animation. They are GameObjects with one sprite that doesn't change at all. The only code attached to them is a script that says whether or not it causes damage and a circle collider 2D.
If anyone knows why up to 20 of this graphic would cause major lag, it would be very much appreciated. I'll keep looking around from my end. :-)
I'm not sure why this worked, but it did...
In the Sprite Renderer inspector panel, there is a section for a material. I had left that material as the default ("Sprites-Default"). When I changed it to a material that matched the sprite, the lag nearly dropped completely. I am now sitting at 45 fps. It's still not ideal, so I'm still looking into other potential solutions. :-/