Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: alexei on August 22, 2013, 04:52:00 AM

Title: Need help with calling tween method
Post by: alexei on August 22, 2013, 04:52:00 AM
Hi, I'm trying to use the use the tweens with ease in/out but I cant seem to call them.

   private TweenScale tweenObject;

void callTween() {
      tweenObject.from = new Vector3(0f,0f,0f);
      tweenObject.to = new Vector3(1f,1f,1f);
      tweenObject.method = UITweener.Method.EaseOut;
      tweenObject.Play(true);
}

when I try to use the function:
NullReferenceException: Object reference not set to an instance of an object

Pls help
Title: Re: Need help with calling tween method
Post by: ArenMook on August 22, 2013, 10:19:40 AM
You shouldn't be referencing a tween.

Use TweenScale.Begin.
Title: Re: Need help with calling tween method
Post by: alexei on August 22, 2013, 09:38:10 PM
Sorry I'm a little weak in programming and I still have not understand fully on how to use NGUI yet.

how do i call the method,from,to and delay using TweenScale.Begin?
Title: Re: Need help with calling tween method
Post by: sisso on August 23, 2013, 08:17:18 AM
Open TweenScale.cs and search for static method Begin. Now you know what parameters you could use, and what its return. If you want something different from parameters, it must be applied in the return object. Ex:

  1. var tween = TweenScale.Begin(banner, 1f, Vector3.one * 2f);
  2. tween.from = Vector3.one * 0.5f;

Because it is a simple concept in programing, take a time to study, It will allow you be able to workround some simple problems.
Title: Re: Need help with calling tween method
Post by: alexei on September 24, 2013, 05:34:20 AM
Hi, this time I would like to define the tweening during awake but I am having trouble regarding TweenRotation.

  1. TweenRotation rotateA;
  2. TweenRotation rotateB;
  3.        
  4.         void Awake(){
  5.                 rotateA.from = Vector3.zero;
  6.                 rotateA.to = Quaternion.Euler(new Vector3(0,0,180));
  7.                 rotateA.onFinished(rotateB);
  8.         }
  9.        
  10.         void onRotateA(){
  11.                 rotateA = TweenRotation.Begin(gameObject,4f);
  12.         }

I get the following error with the code above:

rotateA.to = Quaternion.Euler(new Vector3(0,0,180));
error CS0411: The type arguments for method `UITweener.Begin<T>(UnityEngine.GameObject, float)' cannot be inferred from the usage. Try specifying the type arguments explicitly

rotateA = TweenRotation.Begin(gameObject,4f);
error CS0411: The type arguments for method `UITweener.Begin<T>(UnityEngine.GameObject, float)' cannot be inferred from the usage. Try specifying the type arguments explicitly

The problem seems to occur when the .to is looking for a Vector3 but the .Begin() part requires it to be a Quaternion instead... Setting the .to part to Vector doesn't help much either. Did I do something wrong with the algorithm?

Btw, would also like to know the correct method of using .onFinished(). is it the same way as i have written as above or it was wrong too? asking just in case the problem above is fixed but the onFinished() is wrong again and I have to spend another day waiting reply. Thanks for taking your time trying to help though
Title: Re: Need help with calling tween method
Post by: ArenMook on September 24, 2013, 01:56:56 PM
You shouldn't specify 'from' and 'to', and you shouldn't set anything in Awake. Also, don't bother attaching the tween component to begin with. You start the tween like so, by specifying "from" and "to" to it:
  1. TweenRotation tween = TweenRotation.Begin(gameObject, to, 4f);
  2. tween.from = from;
  3.  
Doing so creates the tween for you.

Now that you have a reference to this tween, you can modify it further, including setting your OnFinished callback.
Title: Re: Need help with calling tween method
Post by: alexei on September 24, 2013, 10:03:13 PM
Sorry, I'm kinda getting lost here. I tried to use the line you have given me but there were a few errors:

error CS0103: The name `from' does not exist in the current context
error CS0103: The name `to' does not exist in the current context
error CS1501: No overload for method `Begin' takes `4' arguments

The reason I was set those in Awake is so that i could declare or preset the tween so that I could define the tween sequence for multiple sequential tween (eg:tweenA -> tweenB->tweenC) using OnFinished. If they were declared directly using TweenRotation tween = TweenRotation.Begin() for example then the tweens will be played directly when start... this is also part of the reason I'm asking did I did the OnFinished() correctly.

If I can only declare a reference within a function, and declare them using Begin(), it seems like they are conflicting each other because they will play together when they are first declared. if they could only be declared together within a same function and play together when they are created, how is  OnFinished() supposed to be used efficiently? I mean the other tweens must be played before the time they should actually be used....
Title: Re: Need help with calling tween method
Post by: ArenMook on September 25, 2013, 06:30:25 PM
...

Of course 'from' and 'to' doesn't exist. This is pseudocode. The "from" and "to" need to be replaced with your own values -- that of quaternions in this case.

If you are this weak in programming, don't even try to do this via code. Upgrade to NGUI 3.0 and watch the video tutorial for it. It explains how to activate tweens solely from the inspector, trigering them from basic actions.
Title: Re: Need help with calling tween method
Post by: alexei on September 25, 2013, 10:52:54 PM
...

Of course 'from' and 'to' doesn't exist. This is pseudocode. The "from" and "to" need to be replaced with your own values -- that of quaternions in this case.

If you are this weak in programming, don't even try to do this via code.
...

I did assume that what you gave me was a pseudocode or something when I first gotten the errors from testing and I did replaced them to quartenions. However, because it is still wrong hence I have to assume that what you gave me was the correct method and post the given errors instead. I believe that was a reasonable conclusion. It was only until you replied me again and edited the code that it became more correct.......

I may be weak in programming but I am still trying to learn. However, if it is alright with you I do hope you can be kind enough to provide some sort of explanation or solution when a question is asked. I tried to question certain parts that I do not understand and explain why I don't and I tried to troubleshoot with it...

I have used actionscript and iTween a little before hence that might be the reason I'm lost in using NGUI's tween. They are able to continue their chains of tweens by calling another function when they have completed the tweens. On the other hand, NGUI's OnFinished() calls another UITweener when it is completed. So I'm confused because as stated before: The UITweeners seem like they will be played to together because they are created together using .Begin() in the same function. If that was the case, how is OnFinished() suppose to be used when the tweens are already played before they should be used.

In my previous project I ended up using series of StartCoroutines to simulate the chains of tweens. But that was not the most efficient method because the timing and delay variables would make the codes very messy and hard to manage. Things would be much cleaner and efficient if I could have known how to use the OnFinished() method. However there is not much documentation about it hence I'm trying to seek for guidance.
Title: Re: Need help with calling tween method
Post by: ArenMook on September 26, 2013, 04:19:20 PM
As I said, update to NGUI 3.0. Watch the video tutorial for it. It does all kinds of things in it with tweens, including triggering tweens one after another, and triggering multiple things from the same tween's finished call.

I understand that you are trying to learn, but I cannot teach programming here. This is a support forum for NGUI, and I can only point you in the right direction. I can't sit here and explain C#.

At the very least you need to be able to figure out what's wrong yourself just by reading the error messages you get. For example, this one:
Quote
error CS0103: The name `from' does not exist in the current context
...it tells you that 'from' doesn't exist. Look at the code. What's 'from'? It's not defined anywhere. So define it, set it to something.

Next one:
Quote
error CS1501: No overload for method `Begin' takes `4' arguments
It tells you that the Begin method doesn't take 4 arguments. Right click on the Begin method. Go to its definition. Bam! You can now see the function you are trying to call, including the parameters it expects. You should be able to figure out the rest.

I can't teach you the basics like this. That's not my job. I'd go insane if I had to do that for people.
Title: Re: Need help with calling tween method
Post by: alexei on September 26, 2013, 10:08:16 PM
I understand that you have your situations but I think that doesn't help justifying that you gave a wrong solution and expect the person in trouble to troubleshoot back. But lets drop this from&to part and consider it case closed.

I agree and fully understand that it really is not your duty to teach programming. But for now this really is a matter of troubleshooting because as I have stated many times I can't figure a valid to method to use that OnFinished(). I'm not sure why you are always ignoring it but without you explaining or even getting in touch with the issue, I keep having the bad taste that think that function is simply broken and you are avoiding the topic. I'm sure that is not the case but it really does leave a bad taste like this...

I have tried to update to 3.0 once but maybe my process was wrong while updating I had some problems with the manipulation controls of the panels and widgets after updating hence I revert back to 2.7. I'll give it a try again if there is really no point in using that OnFinished() for whatever reason. This tweening part is almost the final part I need and my deadline is getting closer too.
Title: Re: Need help with calling tween method
Post by: ArenMook on September 27, 2013, 06:38:53 PM
There are three reasons I keep telling you to upgrade to 3.0. First reason, as I've stated, is because it's much easier for non-programmers, or beginner programmers -- in other words, easier for you.

The second reason is, as sisso pointed out, is because what you're asking can be figured out on your own in seconds just by going to the definition of the class (http://tasharen.com/ngui/docs264/class_u_i_tweener.html#ac5c64a91f1081d43e14f2d6e769aca3e), and/or by reading the messages the compiler spits out at you when you do something wrong then pasting them into google (https://www.google.com/search?q=No+overload+for+method+%60Begin'+takes&ie=utf-8&oe=utf-8&aq=t).

I am not the kind of guy that keeps giving people fish. I'd rather have them learn how to fish themselves.

The last reason is I want to give advice on how to use the latest version, not an old version, because as the time goes on, my response here is going to be less and less helpful to others.

But hey, if you want the fish... here:
  1. using UnityEngine;
  2.  
  3. public class MyTweenTest : MonoBehaviour
  4. {
  5.     void Start()
  6.     {
  7.         TweenRotation tr = TweenRotation.Begin(gameObject, Quaternion.Euler(0, 90f, 0), 1f);
  8.         tr.onFinished = MyOnFinishedFunction;
  9.     }
  10.  
  11.     void MyOnFinishedFunction (UITweener tween)
  12.     {
  13.         Debug.Log(tween.name + " has finished!");
  14.     }
  15. }
Although I sincerely hope that you will take the time to learn the basics before trying to move forward.