Forum rules - please read before posting.

Animation (Wait Until Finish) Long Delay - Unity 2019

Hello all,

I don't know if anyone has been using Adventure Creator with the newest version of Unity 2019.3.0a8 Personal (AC 1.68.3), but I've encountered a bug that occurs when "Wait Until Finish" is checked in a Player's unique animation. See screenshot and gif:

https://imgur.com/a/aL5rGLu

Before, when I was using Unit 2018 versions and before, I never encountered this bug. If you patiently watch the gif above (ignore the jerky movements, that always happens when I screen-grab a gif), there is a long delay after the player's pick-up animation plays, after which the "New Item" menu appears. It should be instantaneous; Pick-up animation finishes, sound plays, sprite disappears, menu displays then disappears. Done.

If I uncheck the "Wait Until Finish" box, then it all plays smoothly -- then of course, the sound plays too soon and the item disappears too soon as well. It seems to happen most of the time, yet, there are occasions it does not occur -- and this is playing the same animation "DexterPickUp_U".

Also of note:** this occurs ONLY when playing the game in the Game window, not in builds. **In builds, it seems to work fine. Of course, in order to properly develop, it must work in the Game window.

I know I am using a new alpha version of Unity, but this has occurred with 2019 versions of Unity for me. I waited to see if there was going to be a bug-fix release, but I wanted to bring it to the community's attention.

Any thoughts? Any questions?

Comments

  • edited July 2019

    The character uses "Sprites Unity" animation?

    Is the animation itself set to loop? It may be a Unity issue.

    From the sounds of it, a recreation would involve loading the 2D Demo and checking "Wait until finish" in the same Action type in the "Worm_Use" interaction. However, this does not occur for me - can you tell me what the effect is of this for you?

  • Hello Chris,

    Thanks for getting back with me. I apologize for not including more information about the animation.

    I am using "Sprites Unity" for all animation in my game, and the unique "Use", "Pick-up", and "Reach" animations for my player are not set to loop. I have found that setting them to loop risks that they will play multiple times, even with "Wait until finish" checked.

    Interestingly, I have two computers (both Macs) and I have encountered the above issue when opening the project on both of them.

    Now the 2D Demo: the demo works fine. However, I'm curious as to why in the Demo both "BrainTakeGround_DR" and "BrainPush" are set to loop, when they only need to be played once (unlike a talking or walking animation)?

    So, I attempted to recreate the way I use my Player animations. In the 2D Demo, I un-checked "loop" in the "BrainTakeGround_DR" animation. Then in the ActionList for "Worm_Use", I did the following:

    • I checked "Wait until Finish" and "Return to Idle" for the Player animation
    • I removed the "Engine_Wait"(0.37) action
    • I removed the "Character_Animate: Return to Idle" action

    Then when Brain goes to pick up the worm, he doesn't even animate. The sound plays, the hotspot disappears, the object disappears, and the item enters his inventory. But again, Brain doesn't animate. Is that strange? Am I missing something?

    After which, I tried the inverse: I tried to recreate the way the 2D Demo is set up in my game, but I run into the same problem. With "Loop" checked, the Player animation will play many times before reaching the next action in the Action List hierarchy. Thus, the problem described in my initial report persists.

    Any ideas? Am I missing any details? Have I developed bad AC habits in my own little bubble?

  • Thanks for the added info.

    You're correct in that it's best practice for the animations to be non-looped. However, this has no effect on my end for the 2D Demo after making the ActionList changes you mention. Both looped and non-looped, the behaviour is as expected.

    Try the same changes in a fresh Unity project - as it may be that this is related to your Time (or other) Project settings. If it works then, we can look to see what the difference might be in your own project.

    One other point to mention is that it's worth considering the use of Timeline to play such "one-off" animations, as it frees up the number of animations needed in your Player's Controller - and thus improves performance/load times.

  • Thank you so much for responding. I apologize I didn't get to respond to you yesterday. I had a busy day at my actual job, and I wanted to thoroughly check everything you mentioned before responding back to you.

    When I ran the 2D Demo initially, I did so in a brand new project. (In fact, in Unity Hub, I now have a project just for that 2D Demo, for testing purposes. Thanks for the idea!) When I played around with the demo, I ran into the issue I described above: un-checking loop for the BrainTakeGround_DR animation, setting it to "Wait until finish" and "Return to Idle", adjusting the "Worm_Use" actions... this yielded the result I described -- the animation for Brain didn't even play. I tried it over and over. Nothing. It was so strange.

    You mentioned my project's "Time"... you must be referring to this (this is my own projects time):

    https://imgur.com/npuos6a

    Is there something you think I should adjust?

    To be honest, I have not employed Timeline at all in my project. I have watched a few videos about how to us it (including yours). Definitely something I would love to use in my next project once I become more acquainted with it.

    Still stumped as to what's causing the same animation to have a long delay after it plays sometimes, and then at other times it's perfectly normal. In fact, today I went back and played the same scene that I included in that original gif, and the animation did not have a delay. However, when moving to another scene, the delay occurred again. And to reiterate, this is only occurring in Unity 2019 versions.

    Any response is much appreciated. Your asset is truly the best! Thanks.

  • If you made no adjustments to your Time settings, then no - there won't be anything to change there.

    It's a difficult one to pin down, as at this point it's hard to say if the issue lies with Unity or AC. I'm leaning towards the former as there is a difference in behaviour between builds and the Editor. That it doesn't occur every time in the Editor, too, adds to the problem.

    I would need to know how to reliably recreate the issue on my end. I shall continue to investigate, but if you can learn exactly what conditions are necessary for it to occur (or not occur), then that will give us the best chance.

    You mentioned above you were using an alpha release. What Unity version were you using for the 2D Demo project that you found the same issue with?

    Since it (so far) only occurs on your end, it'd be worth doing some debug-logging to try to reveal a bit more. In AnimEngine_SpritesUnity.cs, you should find the following on line 375:

    float timeLeft = (1f - character.GetAnimator ().GetCurrentAnimatorStateInfo (action.layerInt).normalizedTime) * totalLength;
    

    Immediately below it, paste the following:

    Debug.Log ("Character: " + character.GetName () + ", Total anim length: " + totalLength + ", Normalized: " + character.GetAnimator ().GetCurrentAnimatorStateInfo (action.layerInt).normalizedTime + ", Time left: " + timeLeft);
    

    That'll cause a (very long) list of messages to appear in the Console. Going back to your original project / scenario, what is being displayed during the long wait?

  • I very much appreciate each and every response you give to this community. Thank you thank you. Allow me to answer and address both of your points:

    • What Unity version have I encountered this problem in? -- My current build is 2019.3.0a8 but I also encountered the same issue with 2019.1.10f1

    Debug-log -- This was very useful. I hope other AC users will be able to utilize this code to debug their animations. I have implemented your code following line 375 in the AnimEngine_SpritesUnity.cs file. Here are the results ("Dexter 2" is the name of the Player):

    • The Animations played with no delay: the first time I played the game and picked up that item, the animation played correctly. Here is what the debug log produced in that case: https://imgur.com/a/se0fAsv
    • The Animation delayed: the second time I played the game and picked up that item, the animation produced the delay described in my initial post. Here is what the debug log produced in that case: https://imgur.com/a/fhyWHD5

    As can be seen, there is a clear difference where it says "Normalized" and "Time Left". Keep in mind, this is the exact same animation played (DexterPickUp_U), in the exact same moment in the game, changing nothing in each instance.

    I look forward to any help or insight you may be able to provide. Thanks!

  • What is the duration of the "idle" animation that your Player is playing before the one-off animation is triggered? I would be willing to bet it is 14.6 seconds.

    For whatever reason, it seems that it is taking more than a frame for the Animator to switch over to the custom animation. Slightly above this script change on line 364, test replacing:

    return (action.defaultPauseTime);
    

    with:

    return (0.2f);
    
  • Thanks again for the response Chris. Very interesting insights here. So, I replaced "return (action.defaultPauseTime);" with "return (0.2f);" and it works! The Player's animation performs flawlessly in perfect time. Perfect. Do you think I should leave the line "return (0.2f);" in the game?

    Interestingly, the DexterIdle_U animation (which is the animation playing before DexterPickUp_U) only lasts 1.0 second. However, the DexterIdle_R animation is the one that lasts 14.6 seconds. Why do you think AC would be waiting for that animation to finish when it wasn't even running it?

    On a similar note, it may be that "Wait Until Finish" on Animate:SpritesUnity action has an issue in general. I have noticed that it seems to be ignored by other animations as well. You can see this at the following link (ActionList and Gif):

    https://imgur.com/a/H1xM2P5

    Here are the things that should happen:

    1. Player is Teleported Out of Scene
    2. A delicately placed Animator makes it look like the Player gets into the Log Boat (this animation is NOT set to loop). Waits until finished.
    3. Animator from action 1 plays "idle" which is just a small transparent block looping, thus making it "disappear".
    4. Simultaneously with number 2, the NPC "Log NPC" changes its idle state to include a sized version of what looks like to be the player.

    In the gif, it can be seen that "Wait Until Finish" on action 1 is being ignored. It skips to action 3, and doesn't even play action 2. This is something that started to occur simultaneously with the issue I described earlier. Do you think there is an issue with "Wait Until Finish" on Animate:SpritesUnity action?

    I appreciate your excellent communication and I look forward to hearing back from you.

  • The Object: Animate Action performs a wait in the same manner as Character: Animate. You can apply the same "fix" by modifying line 594 in the same way.

    However, that the log appears to reference an animation not being played suggests an issue on the Unity side. I'd be cautious about implementing such a change officially at this stage - especially as I can't as yet recreate this on my end.

    A perhaps safer way to mitigate this would be the following. Let me know the effect of changing the above, and then re-import the file from the Asset Store to revert back.

    Then, above the line 373:

    // Calc how much longer left to wait
    

    Insert the following:

    if (character.GetAnimator ().IsInTransition (action.layerInt)) return action.defaultPauseTime;
    

    Then, replace the code block on lines 608 - 611:

    if (action.runtimeAnimator.GetCurrentAnimatorStateInfo (action.layerInt).normalizedTime < 1f)
    {
        return (action.defaultPauseTime / 6f);
    }
    

    With the following:

    if (action.runtimeAnimator.IsInTransition (action.layerInt) || action.runtimeAnimator.GetCurrentAnimatorStateInfo (action.layerInt).normalizedTime < 1f)
    {
        return action.defaultPauseTime;
    }
    

    What is the behaviour of both Actions afterwards?

  • Thanks Chris. Replacing the code at lines 364 and 594 with "return (0.2f);" did the trick. It solved every SpritesUnity Animation problem in the game (that I have tested). The secondary Player animations and other object animations respect "Wait Until Finish". Things are playing smoothly.

    To test your other suggestion: I reimported AC, reverting all scripts back to normal. Then, I went ahead and tried the other adjustments you mentioned (adding the line above 373 and replacing lines 608-611). This unfortunately did not solve either issue -- neither the secondary Player animation delay issue, nor the issue I sent of the log-ride animation (Wait Until Finish). Both issues persisted.

    Should we call it "solved" and wait for the next stable release of Unity? In the meantime, I can keep the adjustments you suggested (return (0.2f);) to my own project. Thank you so much for your excellent support. Best asset out there!

  • Unfortunately, that this was occuring for you also in the stable 2019.1 release suggests this won't be changed anytime soon - so I'd like to find a more stable workaround.

    Apologies for asking more, but if you are able - can you try a couple of more replacements?

    Instead of return 0.2f;, try - in turn - return Time.fixedDeltaTime; and return Time.fixedDeltaTime * 2f;. Do either of those things contiue to see things resolved?

  • Again, much appreciated. I replaced lines 364 and 594 with return Time.fixedDeltaTime;. This solved most animation "Wait Until Finish" issues. However, I noticed some of the object animations not behaving as they should. So, I changed line 594 to return Time.fixedDeltaTime * 2f; and this solved the issue.

    With those two lines in place, my animations seem to be running smoothly across all instances (although I haven't played the whole game through, but everything seems good now).

    On another note, I wanted to try some of the things we discussed in previous builds. So, I made a copy of my project and tried to downgrade to Unity 2019.1.11f1. This yielded a very bizarre result -- Adventure Creator is imported, yet not really in the project. What I mean by this is that the "Adventure Creator" tab at the top of the screen nestled between "Component" and "Window" is not there. Nor does there seem any way to get the project to use AC. This is super weird. I've never downgraded to an earlier version of Unity, so maybe I did something wrong. But I tried it twice and got the same result. I looked on the Forum to see if anyone else experienced this, but I couldn't find anything. If you can direct me towards a solution of the weird downgrading issue, that would be great.

    I still have my precious Unity 2019.3.0a8 build that works wonderfully with the changes you have suggested.

    I hope this is helpful. I am extremely grateful for your support. Thanks!

  • Another thing I want to add is that I'm encountering the following in the console (although, there doesn't visibly appear to any effect in the game, nor can I pinpoint what's triggering it):

    • Internal: JobTempAlloc has allocations that are more than 4 frames old - this is not allowed and likely a leak
    • Internal: deleting an allocation that is older than its permitted lifetime of 4 frames (age = 5)
  • Thanks for the testing.

    If AC is imported into your project, but the "Adventure Creator" toolbar menu isn't showing, then there's a compilation error. In Edit mode, clear the Console and see what Error messages remain.

  • Much appreciated. At this point, I can continue on. I'll fiddle around with those previous builds in order to increase my knowledge of downgrading. Thank you so much for your support Chris!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.