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 pg_CSE · Jan 09, 2013 at 07:55 PM · instantiate prefabspeed issuesrenderer.enabled

animation.speed does not work when disabling/enabling renderer

Hi,

The scenario I have is: I've imported an animation and I am pausing/playing using animation.speed (animation.speed = 1 - Plays, animation = 0 - Pauses). This part works fine. I also wanted to have the animation disappear while it is paused. When I disable the renderer for the components in the animated model the model does disappear correctly but animation continues to play and it not at the pause point when I reset the animation.speed back to 1 and enable the renderer for the compnents. I am setting animation.speed to 0 before cycling through all the children of the object and disabling the renderer for each component.

I wanted to find out why disabling the renderer is effecting the speed value for the animation or is it an issue on how I am instantiating the prefab

Notes

  • I have the animation/model defined as a public GameObject and it is set in the inspector

  • I've checked that I am getting the correct instance name and the correct renderer states and also
    verified that the animation.speed value is getting set correctly on Pause to 0 and then back to 1

  • The animation object is instantiated when the user presses a button to play the animation (routine called from OnGUI()) and then the animation starts playing.

  • The Pause/Play work fine as long as I do not disable the renderer for the object components.

  • The Pause/Play code are separate routines called from inside the Update() function.

Has anyone run into this issue or have any suggestions. Thanks! (Please note, this is the first time I've posted in Unity Answers)

The basic code snippets are below.

     public GameObject Model;   //Prefab set in the Inspector
     ..
     ..
     
     Code to instantiate the object:
     
     AnimationInstance = (GameObject)Instantiate(Model,transform.position, transform.rotation)

....

   AnimationInstance.animation.Play();
     
     
     
     Code for Pausing the animation and disabling the renderer
     
                   AnimationInstance.animation["Take 001"].speed = 0.0f;
                 
             
             Renderer[] rendererComponentsOff = AnimationInstance.GetComponentsInChildren<Renderer>();
             
                 // Disable rendering:
                 foreach (Renderer componentOff in rendererComponentsOff) {
                //Debug.Log("COMPONENT NAME for renderOFF = false: " + componentOff.name);
                       componentOff.enabled = false;
                 }    
 
 Code for starting the animation back up from the pause point 
 
         AnimationInstance.animation["Take 001"].speed = 1.0f;
                 
         Renderer[] rendererComponentsOn = AnimationInstance.GetComponentsInChildren<Renderer>();
         
                         // Disable rendering:
                         foreach (Renderer componentOn in rendererComponentsOn) {
                         //Debug.Log("COMPONENT NAME for renderON = true " + componentOn.name);
                             componentOn.enabled = true;
                         }
             
Comment
Add comment
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

1 Reply

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

Answer by PAEvenson · Jan 09, 2013 at 10:01 PM

Your instantiate is fine. I would suggest recording the animations time when you pause the animation and set the time when you replay the animation after a pause. To get the time its:

 AnimationInstance.animation["Take 001"].time
Comment
Add comment · Show 6 · 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 pg_CSE · Jan 10, 2013 at 03:30 PM 0
Share

Thanks for the info. I tried using pauseTime = AnimationInstance.animation["Take 001"].time to get the pause time but I get the same result when I try to resume the animation after disabling/enabling the renderer for the components. If I comment out the disable/enable renderer code then using AnimationInstance.animation["Take 001"].time works fine and the animation will resume playing from the paused time (pauseTime)

There's is something about disabling the renderer that is effecting it. I thought if you disable the renderer you still have the ability to work on the object (as opposed to making the object inactive - ex. AnimationInstance.active = false.)

avatar image PAEvenson · Jan 10, 2013 at 03:33 PM 1
Share

did you try turning the renderers on BEFORE you set the time or resume the animation?

avatar image pg_CSE · Jan 10, 2013 at 03:39 PM 0
Share

Yes, I've tried that, the way I have it is:

On Pause: get the current time of the animation turn off renderers

On resume: Turn on renderes play animation from pauseTime

avatar image PAEvenson · Jan 10, 2013 at 03:50 PM 1
Share

Youre not calling Play() are you? This will restart it. All you want to do when you resume is set the speed and the time.

avatar image pg_CSE · Jan 10, 2013 at 04:12 PM 0
Share

No, I'm not calling Play(). Below is the new code for resu$$anonymous$$g the animation. It's as if the animation continues to play in the background after I've set the speed to 0 to pause. When I re-enable the renderer, set speed back to 1 and resume at the specific pauseTime the animation is at whatever point it would be in the timeline as if the pause never happened.

Renderer[] rendererComponentsOn = AnimationInstance.GetComponentsInChildren();

// Disable rendering: foreach (Renderer componentOn in rendererComponentsOn) { componentOn.enabled = true; } AnimationInstance.animation["Take 001"].speed = 1.0f; AnimationInstance.animation["Take 001"].time = pausedTime;

Show more comments

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

9 People are following this question.

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

Related Questions

Show and hide object according to camera rotation.y position 1 Answer

2D project - player respawn delay problem 0 Answers

Why does scripting backend slow down android app? 1 Answer

How to replace prefab at the same location? 1 Answer

Instantiated Object does not fall 3 Answers


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