|
Hey all, The current project I am working on has animated menus, which are not programmatic but instead use Unity's Animation tool. There are also nicely animated transitions that occur between screens, also utilizing the Animation tool. We are using Time.timeScale and setting it to 0 as a solution for pausing the game, in which case the Animations stop as well. This doesn't surprise me and it makes sense why this would happen, but it does cause problems when we're trying to play these animations during the pause screen. Does anyone have a solution for this? I've done some digging for this and it seems like everything I have found would work for programmatic animations, but not Unity's Animation Clips. Thanks in advance. ==
(comments are locked)
|
|
First off I wanted to thank @Eric5h5, @Paulius Liekis and @Herman Tulleken for the answers. I actually used a mixture of solutions. Basically, I had so much code invested in FixedUpdate, etc. That the pausing solution needed to remain the way it was. Inside my base animation manager class I adjusted the code so that animations run independently of Time.timeScale. I used a spin of Paulius and Herman's methods to achieve this. This class is a more basic version of what I had to do to get this to work, it involves 2 animations, an in transition and an out transition.
In this case, I took advantage of Animation States and AnimationState.normalizedTime, using my custom deltaTime (thanks again Herman) to allow the animation to play as expected even if Time.timeScale is set to 0. Since these are straight-forward, linear animations, I was able to get away with setting the AnimationState's values in PlayAnimation the way I did. In other cases I'd probably want to inject more parameters. What I also noticed was that I lost connections to my AnimationEvents which I inserted using Unity's Animation Editor. In my case it was a single function call which was fired on completion. Again, because of the linear nature of these animations I was able to get away with just calling that function after the accumulated time reached the length of the animation in my custom update loop. I hope this helps anyone else with a similar complication. I was lucky that I only had to modify a single class and everything worked as expected. I have good class and package structure to thank for that. :) Chances are you may need to modify the code above to fit your needs but I hope it serves as a stable launch point for you. Cheers == This is what I want!! Its GREAT solution. Thank you very much!
Jan 09 '12 at 06:04 PM
GigaDeath
@GigaDeath: And this is not an answer! I've converted your "answer" into a comment.
Jan 28 '12 at 07:32 PM
Bunny83
@JosephPasek, Bunny83, Eric5h5: or anyone else: Is there an equivalent method of doing this, but for Particle Effects, so that they Emit/Animate on Pause Menus?
Apr 20 '12 at 12:22 AM
AbsurdHart
Thanks everyone, very helpful! @AbsurdHart: To turn the above code into an equivalent solution for particle effects, you could try replacing line 34 above with "particleSystem.time = _accumTime", and removing other references to AnimationStates. I haven't tested this myself though. (And yeah, I realise your question is old :) )
Feb 01 at 03:11 AM
dreamychris
i was using this code to run an animation while paused, but i can't run animation events with this, they simply wont run, is there any way around this?
Apr 10 at 01:29 AM
kebrus
(comments are locked)
|
|
Set the timeScale for pausing to something like .00001 instead of 0, and when pausing or resuming set the animation speeds to " Did you mean 1 divided by Time.timeScale or pausing/resuming respectively?
Nov 03 '10 at 11:45 PM
equalsequals
equalsequals: I meant one divided by Time.timeScale. Edited for clarity.
Nov 04 '10 at 01:41 AM
Eric5h5
I just tried this method and it didn't work well at all for me. it worked ok until timescale reached about 0.4, after which there was a mismatch between the normal speed and the paused speed, growing more severe the slower time is set. At 0.0001 the animation played extremely slowly, despite being set to play at 10000 times speed
May 16 '12 at 10:44 PM
RichMakeGame
(comments are locked)
|
|
We use the following (clumsy, but workable) scheme. Most of our simulations run of a separate variable ourOwnDeltaTime, which is the same as Time.deltaTime when the game is running, but 0 when the game is paused. Things that should not pause runs off the proper deltaTime. It is clumsy, because animations and particles have to be played and paused separately (because, of course, internally they still run of Time.deltaTime). It also requires a lot of discipline (you have to remember never to use the Time.deltaTime everywhere), and might not work well with 3rd party code. A benefit is that game speed and interface animations can be controlled separately. I could never understand why there is not a better built-in solution for pausing (in any game-engine I have worked with)... I agree, there should be something internal for this, because every solution I've found is nothing short of a hack. It's unfortunate that those are the only options here. Luckily there is extremely little 3rd party code implemented in this project, and anything that wasn't written in-house is not timescale-dependent. I can implement this custom deltaTime with little to no rework outside of a single class in our animation framework.
Nov 04 '10 at 04:01 PM
equalsequals
(comments are locked)
|
|
You just have to control animation time manually - it works with regular or Unity animations. Get the actual delta time from realtimeSinceStartup or something else that is not affected by time scale and set appropriate time on your animation. Thanks for the idea, it was a nudge in the right direction. I had assumed this was the route I needed to go, but I was looking for something with a little less rigmarole. I submitted my own answer with code as to how I solved this.
Nov 04 '10 at 07:03 PM
equalsequals
(comments are locked)
|
|
Here is my solution for animated tutorial in pause menu. You double-posted your answer. They were around 6h in the moderation queue and just got aproved. I deleted the older post and this is the newest one.
Jan 28 '12 at 07:30 PM
Bunny83
Anyone know how I may apply these to my menu on pause, that uses touch swipes to scroll through a list (moved using transform.Translate)?
Nov 13 '12 at 12:47 PM
StoneFish
(comments are locked)
|
