Hello Guest

Author Topic: Sprites flickering when "dynamic batching" is enabled on Android  (Read 6713 times)

cloudcamaleoniv

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 27
    • View Profile
I'm doing my first professional game for Android, and I think your product was the best one for this situation.

I did some basic tests for Android. And I've got something VERY strange. When I first "build and run" with my device connected, the game ran JUST FINE. But when I quit it, and reopened, the sprites starts flashing forever (just the static-ones, not the animated ones). I thought it must be some caching problem. But even when I restarted my DEVICE, the sprites are STILL flashing. So, I uninstalled the app, installed again AND - first time running, perfect. Exit, open again, sprites flashing forever. What the hell? My game only works in the first time!

So I continued my tests, this time, messing with the "player settings". And I got something curious. When I turn OFF the "Dynamic batching", the game runs just fine. In the first time, second, third, well... the way it always should have worked. So I thought "well... let's just keep this box unchecked". But... It would be very good that this option stays checked, 'cos I know it increases the game performance. So, you guys could explain to me what these flashing are? And why do they happen? And how can I fix this?



So, the problem is that. I'm going to explain what my tests are - I have 2 prefabs, the first is a "Walls" prefab, and the 2nd is a "Powerups" prefab. These two prefabs are associated with two variables of a Scenario.cs script, which belongs to a GameObject in the scene.

The Scenario.cs script has...
public GameObject wallsPrefab;
public GameObject powerupsPrefab;


The scenario is responsible for creating the GameObjects of the prefabs and moving them along the x-axis. From the right boundarie of the screen to the left. When the sprites get all the way left, they are destroyed.

And that's it. Objects generated from two distinct prefabs that moves from the right side of the screen to the left. These sprites flash all over the scene when the game is run after the first time. And this does not happen when Dynamic Batching is OFF.

Oh yeah, my device is a Motorola Defy (kind of old, but still).

Waiting for an answer. Thanks.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprites flickering when "dynamic batching" is enabled on Android
« Reply #1 on: May 20, 2013, 09:52:37 am »
Sounds very much like a bug in Unity - 2D Toolkit doesn't do anything special with the meshes, they are just normal dynamically generated meshes. What version of Unity are you running? I think it is definitely worth trying the same in a different version of Unity (eg. 3.57 if you're using 4.x, or even the 4.2 beta if you're on the list).

If you get it happening on those platforms, AND it still happens in 4.2 too, I can probably help create a really simple test sample which could be submitted to Unity as a bug report.

I can think of a few ways to try and work around this, but, it is going to be a hack around a Unity bug anyway - probably worth finding out what it is before going any further.

My thoughts on what is happening -
I think the reason the animated ones aren't flashing - is that the mesh is getting regenerated every frame. It isn't with the static ones, and some internal buffer in Unity is using the incorrect data, possibly some vertex buffer which isn't being updated, simply because the objects aren't moving.

cloudcamaleoniv

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: Sprites flickering when "dynamic batching" is enabled on Android
« Reply #2 on: May 21, 2013, 04:22:22 am »
Oh hell, I tried today all day long to install older versions of Unity, but when I import TKD2ROOT folder into the project, Unity crashes. Tried with 3.5.7, 3.5.6 and 3.5.5.

I don't know... maybe is my cellphone. I'm going to test with another device and I post here the results. Maybe Unity 4.2 is released before I release my game, and I hope it doesn't appear the same bug.

Also, I think it's strange the problem be in Unity, because it works FINE the first time it runs. The problems only appear the second time forward.

Well.... I'll test in another device soon. Cheers.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Sprites flickering when "dynamic batching" is enabled on Android
« Reply #3 on: May 21, 2013, 08:29:34 am »
Please don't copy files from one project to another, especially across Unity versions.
Create a new project, import the 2D Toolkit unitypackage - you can get this from the asset store, or the forum if you've registered.
Copying files from one project to another is almost a sure fire recipe for disaster :)
You should be able to use it in 3.5.7 no problem - that is the version we use for development.

If its a bug in Unity, which is very very likely, it should really be reported - they can't fix what they don't know about ;) That is assuming Unity 4.2 hasn't already fixed it.

cloudcamaleoniv

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: Sprites flickering when "dynamic batching" is enabled on Android
« Reply #4 on: May 24, 2013, 08:21:11 pm »
Well... I did some more tests with what you've said - "Don't copy the folder from one project to another".

I feel kinda stupid right now, lol. But doing that and recreating all the project may be the answer to my problem. The sprites are no longer flickering in the mobile.

Thanks man.