Author Topic: bug or feature?  (Read 15160 times)

Drexster

  • Guest
bug or feature?
« on: June 05, 2012, 04:40:54 AM »
After spending what seems to be hours trying to figure out why I couldn't call an animation on a NGUI widget from script after having been able to successfully play the same animation using "UI Button Play Animation". I figured out that NGUI disables the Animation component of the object after it plays an animation.

This seems odd... no?  ???
Is this intentional? What's the rational for this?

Playing animations from script now requires that I do something like this:
  1. gameHUD01.GetComponent(Animation).enabled = true;
  2. gameHUD01Anim.PlayAnimation("GameHUD_Up");

Which quite frankly doesn't seem very efficient.
Hopefully I'm doing something wrong and can be *shown the way*.  :-\

kaede

  • Guest
Re: bug or feature?
« Reply #1 on: June 05, 2012, 04:53:44 AM »
I play animation by a brute way, always add animation at dialog root ( the gameobject where your dialog start, don't worry, you can give your prefab to your artist, he will build an animation for you ), then write an animation play script for your own, before you play an anmiation, you need to gather all UIAnchor in your dialog ( don't use GetComponentsInChildren, the function will not return properly while the gameObject is disabled, try wrote a gather function your-self ), turn off it and than add an event on your animation, when your animation is done, you'll receive a notification, then turn on your anchors, not any issue ;p

Drexster

  • Guest
Re: bug or feature?
« Reply #2 on: June 05, 2012, 05:09:45 AM »
Thanks for the suggestions Kaede, but I don't quite follow. Not sure what you mean by "dialogue root". I already have an animation play script placed on the object I need to call animations on. Also I'm unsure what UIAnchors have to do with this


The component added by NGUI called "Active Animation" also needs to be disabled for scripted animation events to function properly. Surely this isn't by design.

kaede

  • Guest
Re: bug or feature?
« Reply #3 on: June 05, 2012, 05:22:05 AM »
Thanks for the suggestions Kaede, but I don't quite follow. Not sure what you mean by "dialogue root". I already have an animation play script placed on the object I need to call animations on. Also I'm unsure what UIAnchors have to do with this


The component added by NGUI called "Active Animation" also needs to be disabled for scripted animation events to function properly. Surely this isn't by design.

Well, i mean a dialog root just look like below,
-- UIRoot
-- -- UICamera
-- -- -- YourDialog ( stick your own dialog scripts, generally manger wigets stick on this game Object, i call this object is dialog root )
-- -- -- -- Anchor0
-- -- -- -- -- Panel0
-- -- -- -- -- -- Sprite wigets
-- -- -- -- -- -- Other wigets

Upon my knowledge, UIAnchor will automatically adjust your wigets' position by uiCamera stick on it, i just do an experience on it, if you don't turn off UIAnchor while playing an animation, the transform of widgets will struggle both force of changing its rotation and position, actully you will see your whole dialog oscillation in the screen, for example.

An anmiation that bring a dialog and all its wigets from bottom of screen to upper and than bring it to screen center, you'll see an UIAnchor set with Center alignment mode will drag your dialog to the center of screen by force while the anmiation try to smoothy the kienmatics, this is the source of oscillation that you can see by your own eyes.

Hope it is useful for you.  :P

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: bug or feature?
« Reply #4 on: June 05, 2012, 05:59:51 AM »
Disabling the animation after it finishes playing is just an option on UIButtonPlayAnimation.

Drexster

  • Guest
Re: bug or feature?
« Reply #5 on: June 05, 2012, 02:15:04 PM »
I wish it was that simple. But I've double an triple checked and none of the relevant Buttons have this option enabled. Is there something else that would disable the animation component?

Drexster

  • Guest
Re: bug or feature?
« Reply #6 on: June 05, 2012, 03:46:09 PM »
So if you use UIButton Play Animation, you shouldn't use scripted events to also trigger animations? and that is by design, correct?


There must be something else disabling the animation component, none of my UIButton Play Animation components have "Disable When Finished" set to true.

Drexster

  • Guest
Re: bug or feature?
« Reply #7 on: June 05, 2012, 04:08:17 PM »
My solution so far has been to remove any button references to the Widgets I need to trigger animations on from script. Currently all UIButton Play Animation calls disable the animation component and add a "Active Animation" component, this prevents animations from playing: regardless of what setting "Disable When Finished" is set to.

I've tested this by creating a new button and component, a widget with an animation and trying to call the animation from script after calling the animation from UIButton Play Anim. No dice.

This should probably be looked at as a bug.

Drexster

  • Guest
Re: bug or feature?
« Reply #8 on: June 05, 2012, 04:19:42 PM »
I think we're talking about different things here. I'm not having issues with Anchors, widget positions on screen or anything to do with dialog (still not sure what you mean by this?).

My issue pertains to the use of triggering Unity animations on NGUI objects/widgets from script vs. using NGUI's messaging system. It's seems there's a conflict between NGUI's messaging system and calling animation.play on an object that's had an NGUI event trigger an animation.

Thanks for the suggestions though!

Well, i mean a dialog root just look like below,
-- UIRoot
-- -- UICamera
-- -- -- YourDialog ( stick your own dialog scripts, generally manger wigets stick on this game Object, i call this object is dialog root )
-- -- -- -- Anchor0
-- -- -- -- -- Panel0
-- -- -- -- -- -- Sprite wigets
-- -- -- -- -- -- Other wigets

Upon my knowledge, UIAnchor will automatically adjust your wigets' position by uiCamera stick on it, i just do an experience on it, if you don't turn off UIAnchor while playing an animation, the transform of widgets will struggle both force of changing its rotation and position, actully you will see your whole dialog oscillation in the screen, for example.

An anmiation that bring a dialog and all its wigets from bottom of screen to upper and than bring it to screen center, you'll see an UIAnchor set with Center alignment mode will drag your dialog to the center of screen by force while the anmiation try to smoothy the kienmatics, this is the source of oscillation that you can see by your own eyes.

Hope it is useful for you.  :P
« Last Edit: June 07, 2012, 03:49:14 PM by Drexster »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: bug or feature?
« Reply #9 on: June 05, 2012, 11:29:05 PM »
The only place NGUI will disable your object for you after an animation is line 98 of ActiveAnimation.cs:
  1. if (mDisableDirection != Direction.Toggle && mLastDirection == mDisableDirection)
  2. {
  3.         NGUITools.SetActive(gameObject, false);
  4. }
As the code implies, if the disable condition is set to be after the same direction as the direction in which the animation is playing (forward or reverse), then it will disable it.

I suggest looking at your animation and make sure that it doesn't disable itself at the end. Animations themselves can do that too, you know.

Drexster

  • Guest
Re: bug or feature?
« Reply #10 on: June 06, 2012, 04:24:29 PM »
Thanks, I'll check everything again for the fourth time.
I checked for a rogue key frame that could be enabling/disabling the animation and all scripts in my project. Nothing other then NGUI enables or disables the animation, and this is regardless of how the "Disable When Finished" flag is set. This is why i'm saying it's a bug. It's not working as intended.

This can be demonstrated in a new project with a new UI using the sample Sci-fi atlas. Create a button, add a new animation. Add UIButton Play Animation, mark button as target and animation name, others leave as default. Press play, click button... Is the animation component supposed to disable? At any point? Because for me it does.

  • Putting a print statement at line 99 of ActiveAnimation does not yield anything in the console.
  • Setting the animation to play automatically and disabling the UIButton Play Animation component, allows the animation to play without disabling the Animation component.
    • Enabling the UI Button Play Animation component results in the animation component being disabling when the button is clicked. <- Is this intended?

    edit - NGUI v2.0.7c
« Last Edit: June 06, 2012, 04:32:10 PM by Drexster »

Drexster

  • Guest
Re: bug or feature?
« Reply #11 on: June 15, 2012, 08:01:40 PM »
Any chance of someone else looking into this?
I suspect this is also affecting animation events (in the animation editor/window) from firing properly.
I say that because my animation events are only properly firing where/when i've bypassed NGUIs event messaging.

Any help with this would be hugely appreciated.

Edit - Just did a test in the NGUI Example 3 scene. Created a script with a "test" function to output to log. Added the script to the object with animations, added the events in the animation editor to call the function and sure enough the function does not get called.

Can anyone verify that this is happening on their install as well? Try calling a function using the unity built in animation editor on an object which also has NGUI animation messages occurring. 
« Last Edit: June 15, 2012, 08:13:35 PM by Drexster »

Shorinji

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: bug or feature?
« Reply #12 on: June 17, 2012, 02:16:11 PM »
Hi,
I don't know if i am too late for that but anyway..

To ArenMook,
I think you did not cleary get what Drextser was meaning, he meant the Animation Component gets disabled, not the GameObject.

To Drextser,
I tested on my install, it does the same.
In my opinion it comes from the line 83 of the ActiveAnimation.cs in the version i have:
  1. mAnim.enabled = false;
By commenting it the Animation Component is no longer disabled here.
However, i don't know if ArenMook disabled it on purpose or not, it might be for the "Call When Finished" feature which would use that Animation Component status to detect when it is finished, but I don't have time to check right now.



ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: bug or feature?
« Reply #13 on: June 17, 2012, 06:34:13 PM »
I was on vacation for a week. :P

Disabling the animation component is intentional. There is no need to have it enabled. NGUI animates things independently of time, which means it samples each frame manually rather than simply letting the animation play. This also lets NGUI play animations in reverse.

To trigger an animation, use:

  1. ActiveAnimation.Play(animToPlay, directionToPlayIn);

Simple and effective. Don't touch the Animation component directly.

Drexster

  • Guest
Re: bug or feature?
« Reply #14 on: June 18, 2012, 01:22:20 PM »
I will try this immediately, thanks!

Hope that your trip to DR was awesome, was there last year with the gf and we did nothing but sun bathe on the beach and drink miami vices. Was perfection.