Author Topic: problems with reusing tween scripts  (Read 8663 times)

Spacez

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
problems with reusing tween scripts
« on: November 19, 2013, 11:03:22 AM »
i'm using some tween scripts -- Tween Position, Tween Alpha, Tween Rotation

they work well for the first time i trigger them (for example, when the player lost his hp the tween will be triggered by setting 'enabled'). After the tweens finished, i disable all of them including set the gameobject's 'setactive' to false (in order to hide the missing hp, a heart).

the problem is my game can be continued after the player lost all the hearts. By doing this, i set all of the hearts' setactive to true. And when the player lost his heart again, i do the same thing as i did in the first -- set 'enabled' to true for all Tween scripts. But when i set the enabled to trigger the tweens, the tweens dont work as it should (it should go smoothly from the starting position to the target position), they change the position immediately after the duration. (the problem happens with all the Tweens -- position, rotation, alpha)

here is a picture of my Tween setting.



am i doing something wrong ? :(


Thanks for all the help

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: problems with reusing tween scripts
« Reply #1 on: November 19, 2013, 08:47:05 PM »
If you want tweens to play after they've finished, you should Reset() them first. Enabling the component won't make it start from the beginning.

Spacez

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: problems with reusing tween scripts
« Reply #2 on: November 21, 2013, 09:40:07 AM »
it works! Thanks ArenMook :D


can i ask two more questions (so that i dont have to create more new topics)
1.)
i'm make a game to Android and iOS
i built my game to test in many Android devices (many different specs) such as Galaxy Nexus, S2, Nexus 7, Nexus 5. All of them can run the game (though most of them are having lag issue in GameScene except Nexus 5)
the problem is, when i build my game to iOS and test them in iPad Mini and iPad2, my game crashes after loading from WorldScene to GameScene.
I guess the reason is about memory usage (?), or is there any possibles causes ?  :-\

2.)
as i mentioned about testing the game in many Android devices and it works well in WorldScene except in Nexus 5 (the best spec of all devices) textures are messed up and duplicated (see my attachment).


Is there any ways to fix them (both problems) ?



Thanks again and really appreciate in your help,
Spacez

J450NP13

  • Guest
Re: problems with reusing tween scripts
« Reply #3 on: November 21, 2013, 09:44:44 AM »
I am having the same issue.  How do I reset them???

Should this also be done for the scale tween??

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: problems with reusing tween scripts
« Reply #4 on: November 21, 2013, 02:11:34 PM »
@Spacez: You forgot the attachment, and without any kind of stack trace regarding where it crashes, I can't help you much. If it works everywhere except Nexus 5, then issue is likely in different hardware not being handled well by Unity. Make sure your main camera's clear color's alpha is 255, not 5 like it starts with.

@J4: You do it by calling the Reset() function like I mentioned.

J450NP13

  • Guest
Re: problems with reusing tween scripts
« Reply #5 on: November 21, 2013, 04:19:35 PM »
ArenMook,

How?..lol

I have like 20 buttons and textures using tweens at different times.  How do I call it?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: problems with reusing tween scripts
« Reply #6 on: November 22, 2013, 03:13:56 AM »
Well, how do you activate your tweens? If it's via a button click using the OnClick section of UIButton in inspector, you can have multiple functions in there. Reset() is just one of the functions you can choose on the tweens.

Spacez

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: problems with reusing tween scripts
« Reply #7 on: November 22, 2013, 09:56:14 AM »
sorry, here is the picture of problem 2.)


btw, where is the 'main camera's clear color's alpha' ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: problems with reusing tween scripts
« Reply #8 on: November 22, 2013, 03:51:00 PM »
Yeah looks like clear color related. It's the very first parameter on your Camera in the inspector: "Clear Flags". UI cameras have it on "Depth Only" by default. This means that there must be another camera drawn first -- your game camera, and it must have Clear Flags set to "Color" or "Skybox", with the color specified right below it. By default Unity makes this color 5 out of 255 for legacy reasons, which breaks certain devices.

Spacez

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: problems with reusing tween scripts
« Reply #9 on: November 23, 2013, 06:05:55 AM »
changed to Solid Color with Alpha 255 and it works !
Thanks again :D



about another problem

Quote
1.)
i'm make a game to Android and iOS
i built my game to test in many Android devices (many different specs) such as Galaxy Nexus, S2, Nexus 7, Nexus 5. All of them can run the game (though most of them are having lag issue in GameScene except Nexus 5)
the problem is, when i build my game to iOS and test them in iPad Mini and iPad2, my game crashes after loading from WorldScene to GameScene.
I guess the reason is about memory usage (?), or is there any possibles causes ?


you mentioned "without any kind of stack trace regarding where it crashes, I can't help you much." 
how can i get those information ?


about memory issue, i have my World Scene created using NGUI. I create every page (such as ranking page, shop page, option, etc) in this Scene by 'setactive' some of them to false, some to true.
is the problem occurs because i have every thing instantiated at the same time ? if so, how can i deal with it ?


« Last Edit: November 23, 2013, 06:15:55 AM by Spacez »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: problems with reusing tween scripts
« Reply #10 on: November 23, 2013, 08:35:34 PM »
Well, like I said, without some proper details I can't make a reasonable guess. All I know is that NGUI itself doesn't crash Unity. In fact, crashes in Unity are generally caused by something much more serious like blowing through the memory usage.