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
2
Question by saud_ahmed020 · Apr 01, 2015 at 03:27 PM · animationscene-loadingexecute

Why animations are not playing when I go back to previous scene?

Hi Unity Gurus!

I have 2 scenes in my game.

1) MainManu scene
2) Gameplay scene

I am playing animation "Avatar Animation" and "Some leaves" in "MainManu" scene . Avatar animates idle animation and leaves are moving from left to right. Now, When "MainManu" scene executes first time, all animations are working. But, when I go back from gameplay scene to "MainManu" scene animation are not working. Have you any idea about it??

Comment
Add comment · Show 2
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 TRG96 · Apr 01, 2015 at 03:31 PM 0
Share

post the code for how you are playing the animations.

avatar image saud_ahmed020 · Apr 01, 2015 at 03:39 PM 0
Share

Following code is for leaf movement from left to right.

     private Vector3 startRotation;
     private Vector3 startPosition;
 
     Transform _t;
 
     public float speed;
     public float $$anonymous$$Speed;
     public float maxSpeed;
 
     void Awake()
     {
         _t = transform;
         startPosition = _t.position;
         startRotation = _t.eulerAngles;
         speed = Random.Range($$anonymous$$Speed, maxSpeed);
 
     }
     
     void Update ()
     {
         Vector3 newRotation = _t.eulerAngles;
         Vector3 newPos = _t.position;
         newPos.x += Time.deltaTime * speed;
 
         newRotation.z = _t.eulerAngles.z + 5;
         _t.eulerAngles = new Vector3(_t.eulerAngles.x,    _t.eulerAngles.y, newRotation.z);
         
         _t.position = newPos;
     }
 
     void OnBecameInvisible()
     {
         _t.position = startPosition;
         _t.eulerAngles = startRotation;
         speed = Random.Range($$anonymous$$Speed,maxSpeed);
     }



2 Replies

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

Answer by Noor-Ali · Apr 14, 2015 at 10:18 AM

If it runs first time but not the second time then you must have done something wrong with global perimeters!

1- If you're moving using thirdparty Tween engine check it's running correctly second time 2- If you're moving manually changing it's transform and you have Time.deltaTime in it. Check your Time.timeScale is "1".

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
avatar image
0

Answer by Diet-Chugg · Apr 01, 2015 at 03:49 PM

from the docs: http://docs.unity3d.com/ScriptReference/MonoBehaviour.Awake.html

Awake is called only once during the lifetime of the script instance

Change Awake() to OnEnable().

from the docs: http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnEnable.html

This function is called when the object becomes enabled and active.

Awake will call only once for the script whereas OnEnable will be called each time you reload the scene as long as the object is not set to DontDestoryOnLoad.

Comment
Add comment · Show 1 · 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
avatar image saud_ahmed020 · Apr 01, 2015 at 04:00 PM 0
Share

Still not working :( I have changed Awake() to OnEnable() and I tested it. You are saying right. When I back to "mainmanu" scene OnEnable() is called but leaf is not moving.

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

22 People are following this question.

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

Related Questions

Inconsistent Scene loading, Armature Rotation problem. 0 Answers

Animation not playing when returning to a previous loaded scene 2 Answers

Can the animation editor create local rotational data? 3 Answers

Does the Singleton GameObject need to be in all scenes where i need to access it? 2 Answers

Execute Random Animations 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