Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ZweiD · Feb 15, 2012 at 08:37 PM · itweenloadleveloncomplete

iTween fires oncomplete twice if LoadLevel in oncomplete

Hello,

contrary to most people I don't have the problem of iTween not calling the oncomplete function at all: For me it is called twice in certain circumstances!

This seems to happen if I load a new level inside the oncomplete function.

Below is a code sample that illustrates the issue:

 public class SmoothLevelChange : MonoBehaviour {
     
     void OnTriggerEnter(Collider other) {
         if(!other.tag.Equals("Player")) return;
 
         GameObject.DontDestroyOnLoad(gameObject);
         // Set GUITexture to cover the Screen
         gameObject.GetComponent<GUITexture>().pixelInset = new Rect(Screen.width/2,Screen.height/2,0,0);
         // fade GUITexture in
         iTween.ColorTo(gameObject, iTween.Hash("a",1, "time",2, "oncomplete","oncomplete"));
     }
     
     void oncomplete() {
         Debug.Log("oncomplete"); // prints twice
         Application.LoadLevel("Scene2");
     }
     
     void OnLevelWasLoaded() {
         Debug.Log("onlevelwasloaded"); // prints twice as well because oncomplete gets called twice
         // ... some setup stuff like positioning the player ...
         // ... and fade back in ...
         //GameObject.Destroy(gameObject);
     }
     
 }

The way I see it is that iTween gets somehow 'restarted' when the new Level loads (there is a noticeable delay between the first and second call of oncomplete).

If you remove the Application.LoadLevel from the oncomplete function it gets called only once (like it should in the first place).

What am I missing here or is it really a bug? And more importantly, how can I fix this behaviour? I want to delete the object after the level was loaded, but I can't because if I do, I'll get an error saying that iTween tries to call a function on a non existing object.

Or is there a better way of fading the screen to black, change the level and then fade the new level back in?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ZweiD · Feb 16, 2012 at 03:32 PM 0
Share

ok, seems like I found my error: after loading the new level, my player collides again with the trigger. therefore the whole event loop is started all over again.

since the link provided by dannyskim is really usefull (thanks for it) I'll mark his answer as correct.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by dannyskim · Feb 15, 2012 at 09:17 PM

Not quite sure why that's happening. But as far as an alternative, you may want to look at:

http://www.unifycommunity.com/wiki/index.php?title=FadeInOut

The above link provides fully functional camera fading utilizing OnGUI and a one-pixel repeated texture tiled across the screen. So, you can use black, or white, up to you.

The one that I prefer to use is ratmat2000's version about 3/4 of the way down the page. Remember, OnGUI uses render texture and is very inefficient and expensive, so if you're targeting mobile platforms I would suggest you cache the script as a variable and enable / disable appropriately after utilizing it.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

itween: firing oncomplete AFTER ONE LOOP 0 Answers

iTween oncomplete method on normal C# class 1 Answer

How to write a simple save script 1 Answer

iTween & Boo 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges