Hello Guest

Author Topic: new sprites are invisible ( or !isVisible ) for two frames  (Read 5341 times)

mrscary

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
new sprites are invisible ( or !isVisible ) for two frames
« on: September 06, 2012, 03:52:50 am »
whether I instantiate a prefab containing a tk2dSprite in code, or drag the prefab into the hierarchy and run the player, or just create a gameObject with a tk2dSprite on it, the tk2dSprite objects are only visible on the 3rd frame... the player on the mac hides the fact that it's not visible, but on an ipad2, you can clearly see when the sprite pops in ( it's a black fade overlay ).

I'm going to assume this is a limitation of Unity?   I'm calling RecalculateBounds() after the mesh is built on the sprite and I've confirmed it's created on the first frame and the bounds are accurate.

This doesn't work so well when you want to display a screen fade overlay.. it pops in after a frame or two.  I've tried a full screen sprite as well as a small sprite.  same thing.

any ideas?

FadeOverlay active: renderer enabled: True bounds: Center: (0.0, 0.0, 0.3), Extents: (1.3, 0.8, 0.0) color: RGBA(1.000, 1.000, 1.000, 1.000) visible: False FrameCount: 1
FadeOverlay active: renderer enabled: True bounds: Center: (0.0, 0.0, 0.3), Extents: (1.3, 0.8, 0.0) color: RGBA(1.000, 1.000, 1.000, 1.000) visible: False FrameCount: 2
FadeOverlay active: renderer enabled: True bounds: Center: (0.0, 0.0, 0.3), Extents: (1.3, 0.8, 0.0) color: RGBA(1.000, 1.000, 1.000, 1.000) visible: True FrameCount: 3

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: new sprites are invisible ( or !isVisible ) for two frames
« Reply #1 on: September 06, 2012, 11:58:04 am »
Interesting. I've not had to deal with this issue before.
What about creating it and disabling it, rather than instantiating it when needed? That might work around the issue.

If the mesh is created, there isn't anything else that happens in the sprite code after that - it is probably safe to assume its something to do with Unity, but then again calling some magical function might make it visible straight away.

To troubleshoot this, what about instantiating a box primitive? Does that do the same thing?

mrscary

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: new sprites are invisible ( or !isVisible ) for two frames
« Reply #2 on: September 06, 2012, 04:24:50 pm »
well it's on scene load that this sprite/fade overlay is visible and then alpha fades away. i.e. frames 1,2,3... Kind of hard to avoid.  I think it'd be the same for a loading screen overlay that you fade away too when the level is finished loading.

right now in ORC, I think this "problem" is covered by the fact that we have some UnloadUnusedAssets and other stuff that's called when the previous scene is still running and somehow, Unity skips frames and it's not apparent.   Our FadeOverlay is a persistent game object which *does* work..  However, every now and then on the first real level load when we instantiate the fade overlay, you can see it.  In this little prototype we're working on, it happens every time, so it's easy to get annoyed by it hehe.

FYI  I tried an FBX mesh that's a quad and rendered to the GUI camera covering the screen.  Same thing.. ( so it's a Unity thing ).  Maybe it's the culling on an orthographic camera or something.

I think the solution is to break down and go back to my GUI.DrawTexture version.. I had tried to eliminate all Unity gui calls from the game, but i think in this case, it won't hurt.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: new sprites are invisible ( or !isVisible ) for two frames
« Reply #3 on: September 06, 2012, 05:17:22 pm »
Seeing that its a unity bug you could ask them at the dev hangout thing in a couple of hours...
Link here if you've not heard of it...
http://bit.ly/PKAoQy