Author Topic: My Tween doesnt work only on android the first time  (Read 7797 times)

nspc

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
My Tween doesnt work only on android the first time
« on: May 30, 2014, 08:26:03 AM »
For recreate the bug in simple condition, I created a little exemple :

Problem :

I have a simple window with one button. when I click the button, a popup window appear with a scale and alpha animation (tweens).
This popup window have a button too, to close him with animation too.

It works perfectly on unity editor and web player. But it doesnt work on android whith my phone the first time I pop the window.
The first time the windows pop without anim, or the anim is very laggy.
After all is ok (I can close, open, after always ok).

So in my complete game there is an ugly menu bug at begin.





I made a rar with the scene and the script (attached file)


or a description :


The main window have : a Widget, with a child : Sprite ,with a child : button : with a child : label

The popup window have : a Widget, with a child : Sprite ,with a child : button : with a child : label

the popup window  have his game object disabled at begin.
the popup window Widget have one tween scale and one tween alpha.

I created a game object with script : MenuManager :

Code :


  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class MenuManager : MonoBehaviour
  5. {
  6.         public UIWidget _popupWindow;
  7.  
  8.         void Update()
  9.         {
  10.                 if ( Input.GetKey(KeyCode.Escape) == true )
  11.                 {
  12.                         Application.Quit();
  13.                 }
  14.         }
  15.  
  16.         public void pop()
  17.         {
  18.                 _popupWindow.gameObject.SetActive(true);
  19.  
  20.  
  21.                 TweenAlpha ta1 = (TweenAlpha)_popupWindow.gameObject.GetComponent("TweenAlpha");
  22.                 ta1.PlayForward();
  23.                
  24.                 TweenScale ta2 = (TweenScale)_popupWindow.gameObject.GetComponent("TweenScale");
  25.                 ta2.PlayForward();     
  26.         }
  27.  
  28.         public void drop()
  29.         {
  30.                 TweenAlpha ta1 = (TweenAlpha)_popupWindow.gameObject.GetComponent("TweenAlpha");
  31.  
  32.                 ta1.PlayReverse();
  33.                
  34.                 TweenScale ta2 = (TweenScale)_popupWindow.gameObject.GetComponent("TweenScale");
  35.                 ta2.PlayReverse();     
  36.         }
  37.  
  38.  
  39. }
  40.  
  41.  

The main window button call "pop()"
The popup window button call "drop()"

I use NGUI 3.5.4 r2
and Unity 4.3.4f1
My phone is Galaxy SIII mini



Is there an other solution or a workaround to fix it ?
thanks



ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: My Tween doesnt work only on android the first time
« Reply #1 on: May 30, 2014, 03:16:33 PM »
What are you scaling from? Scale of 0 is invalid as you can't divide by zero. Use a small number instead like 0.01.

nspc

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: My Tween doesnt work only on android the first time
« Reply #2 on: May 31, 2014, 05:23:48 AM »
I scale from 0.2 to 1

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: My Tween doesnt work only on android the first time
« Reply #3 on: May 31, 2014, 12:51:10 PM »
Ok, so the only issue is that the animation seems laggy the first time you open it? That just seems like the performance of your device, likely related to allocating memory needed to draw the content.

nspc

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: My Tween doesnt work only on android the first time
« Reply #4 on: May 31, 2014, 01:28:28 PM »
Maybe it is that.  Is there a solution to precache memory or something?

When I wait some second before open the first menu (with anim). There is the bug too (and after, the other menus are corrects, like if i dont wait).

So maybe something is init "on the fly" in ngui, the first time we use tweens.
maybe there is a workaround or an option to force the precache (if it is that) ?

ps : I have the pro open source version. So I could add an option if needed

nspc

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: My Tween doesnt work only on android the first time
« Reply #5 on: June 01, 2014, 12:04:50 PM »
No idea what is it? Is somebody have the same problem?

There is an exemple scene in the attached files.

I saw in Tween source files, but i didnt find big instanciation.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: My Tween doesnt work only on android the first time
« Reply #6 on: June 01, 2014, 05:35:50 PM »
When you first show a new UI it will need to create the buffers to draw it, so the first brief slowdown is to be expected. There is no way to avoid it. It shouldn't be more than a few frames, and less than a second total.

nspc

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: My Tween doesnt work only on android the first time
« Reply #7 on: June 24, 2014, 01:37:51 PM »
I found a workaround :
I create a black screen (with black sprite ui) with a label : “loading…”.
Behind this black screen, I open and close all windows with tweens, and after 1s, I hide the black screen.
Sometime it works, and all tweens work without lag, but sometimes not, it still have some lag at begening.
So it is better, but it still have a problem.

Is there a efficient workaround to force precache for all windows during the black screen?

I think some mobiles on android have memory management problems, and everything need to be precache before showed.

Is there a solution to have an efficient precache? This precache can have a 1s duration.

Or can I know when all precaches are ok, and hide the black screen at good moment?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: My Tween doesnt work only on android the first time
« Reply #8 on: June 25, 2014, 06:15:56 AM »
NGUITools.ImmediatelyCreateDrawCalls(panelGameObject);

nspc

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: My Tween doesnt work only on android the first time
« Reply #9 on: July 03, 2014, 07:45:32 AM »
Thank for this function you created, but it doesnt work.

There is an error with a widget with a panel child (there is a scrollView).

In UIPanel OnStart () function :

  1. mLayer = mGo.layer

:NullReferenceException:




ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: My Tween doesnt work only on android the first time
« Reply #10 on: July 04, 2014, 12:57:08 PM »
How are you getting that? Is the object not enabled? "mGo" is set in the Awake() function, which is like a constructor. It's executed as soon as the object is created.