Unity animations are twitchy when transitioning/blending. Any potential fix? - unity3d

Video of issue in action: https://streamable.com/pkrog
The video linked above does a better job of explaining the issue than I could, but I'll give it a shot.
I have my walking/idle animations setup in a 2D Freeform Cartesian Blend Tree, which is working perfectly, aside from when I'm moving between transitions. So idle looks great, until I hold 'W' to move forward, then for the half second it's blending between idle and walking, my model gets very twitchy, then after it's done blending, it's smooth again. Same thing happens every time the Animator has to transition between different animations.
Any idea what could be causing this?

It might have to do with the fact that you update your camera in fixedUpdate and your animations are updated at the game normal update rate. So the different rate at which both your animations and your movement/camera/body updates makes it jittery.

Related

Unity Oculus Quest game stutters/lags when head is moved from side to side

Firstly, I've built for the Quest and checked the Unity profiler - everything seems good.
The weird thing is, when I move my head from side to side I don't see any framerate drops in the profiler but I see a noticeable stutter/lag in the headset. When my head is still or even just rotating, everything looks great, there's no stutter at all.
This stutter only occurs when I'm close to my UI and moving my head. When my head is static or rotating, it's all good. If I move back from the UI, there's no stutter either.
I don't think that it's an issue with too complex geometry or materials, as surely this would show up as a framerate drop in the profiler. I'm guessing that the camera movement is causing some kind of frame mismatch which (for some weird reason) isn't showing up in the profiler.
Does anybody have any ideas as to what might be causing this?
Well, I found the issue after narrowing the issue down to a specific set of GameObjects. It seems that the issue was being caused by a custom 'Dissolve' shader I was using. After setting the shaders back to 'standard' the problem went away! Weird...
This happens if your game FPS is lower than the device refresh rate.
For example if the headset is displaying 90 frames per second and your game is only able to render 70 frames per second, the headset needs to reuse a rendered frame every few frames.
When the game doesn't provide a rendered frame in time the device will just take the last rendered "image" and adjust it to the changed headset position and rotation. If it's a rotation change only, you will not notice, because the headset can easily just rotate the last image. But if it's also movement, the device can't simulate the difference of movement of close objects versus far objects on the image, so if you are moving an object close to a camera (e.g. your hand), it will stay at the same position for two frames (every few frames), which will make it look like it's stuttering.

Unity Animator Checking Too Slow

I'm currently just trying to learn to use the animator within Unity, I'm very in-exp at animation and don't understand it even in the editor as I focus on programming/scripting.
I have an animation and the states for the animations as-well as the conditions all working perfectly however the animation check for the next state is way to slow. I've tried changing the speed of the actual state but it speeds the animation up and makes it look like my character is walking insanely fast.
I've tried messing around with the frames, making them over a longer time period and making the speed of the state faster however it seems to counter act each other, when I make it longer frames the pace of the animation is slow and then when I make the speed of the state go quicker it just makes the frames tick faster making the animation faster.
What I believe is happening is that the check for the next state of animation is happening once the full animation has been played. However what I need is the check to be happening constantly (as if frame by frame of the unity game not the animation).
Any advice would be great, I've tried using youtube to solve this before coming here however most people are creating a platformer game where as I'm trying to aim for a top down 2d, all directional character movement instead of the linear x axis character movement., and outside libraries.
I deeply apologise for my inability to find a suitable source. I have literally just came across an article online that came across a simple solution.
here:https://answers.unity.com/questions/221601/slow-animation-response.html
basically if you can't be bothered to click the link and you are having the same problem,
find exit-time by clicking the transition and then in the inspector and untick it.
Sorry.

Activate Two Cameras At The Same Time

How do I activate 2 cameras at the same time? The first camera follows the character and the second camera follows the character more slowly. After a while we can't see the character with the second camera but the point is each camera renders a special game object. The second camera renders the back game object. So two cameras with each other make better scene moving. Is this possible?
I believe you are looking to implement a scene background parallax where the background appears to be moving across the scene slower than the forground.
Take a look at this video about separating your scene's layers. There is a quick fix solution in the first few minutes of the video, and a longer re-work that is a good idea to think about.
Parallax Scrolling

Unity - LoadLevelAsync hiccups on scene switch

I am trying to make a loading animation while using LoadLevelAsync to load the next scene.
The loading animation is a loading circle that continuously rotates in the middle of the screen, and I use LoadLevelAsync("NextScene") in the code. The problem is that every time right before the scene switch happens the circle will freeze for a few milliseconds before the next scene appears.
I do know that the less things the next scene contains, the shorter the freeze is, but I thought that LoadLevelAsync's purpose was for letting the user experience no lag during scene transitions. My next scene contains a background sprite, some buttons, scripts, and a 3MB audio file. The screen will always freeze for half a second before showing the next scene.
I am using Unity 4.6.3 with Pro feature. I'm also testing the results on a device. I have also tried out the AsyncOperation.allowSceneActivation with Coroutines, and unfortunately they don't work.
If anyone has a solution, or has any suggestions on smooth scene transitions, I would greatly appreciate them.
Thanks in advance.

Bad performance with core animation and view rotations: How to improve?

I have 12 views which I rotate almost similar to the icons in the home screen when going into homescreen-customization-mode by touching an icon for a few seconds.
I use a 3D transformation code to do the rotations. They have each a duration of just 0.02 seconds, and the angle and direction of rotation changes permanently upon acceleration measurements.
5 of those views are fine, but 12 have a very bad performance. Here's the rotation code:
CATransform3D rotatedTransform = CATransform3DRotate(CATransform3DIdentity, degrees * M_PI / 180.0, 0.0f, 0.0f, 1.0f);
self.layer.transform = rotatedTransform;
there's some core animation wrapped around it. But I see a waste of CPU here, since I don't do any 3D stuff. I really only rotate 2D and nothing else. They're simple UIImageViews, but a custom class that does this rotation animations on her own.
I've heared that there are "affine" transforms which are supposed to work for the 2D space. Would you advise to change that to 2D in this case?
Must I prefer to change the transform of the layer, or of the view? which is faster?
Shark it. You must know what exactly is slow to continue.
Try increasing that update interval from 0.02s to something like 0.1s; is that acceptable?
If all of the images are being rotated together, use a sublayerTransform on the super-layer instead of transforming each individually
Try it w/o animations off, just to confirm that your callbacks are working as you expect (setDisableActions: on CATransaction). Do you see the same things as being slow in Shark when you have them off?
If you're doing this inside a scroll view, you might have other problems. You'll need to take care of things going on/off screen, etc.
3d transforms are the same speed as affine ones in core animation AFAIK. basic sin/cos stuff isn't slowing down the app
More information about the actual effect you're trying to achieve would really help to improve performance.
How big on screen are the images?
CALayer rotations are hardware accelerated, 2D and 3D transforms would be pretty similar, no redraws are happening, no need to go to opengl, no need to cache.
Shark would help, but you would need to know what you are looking for, and what you're looking for is not improving the performance of your current code, but removing your code completely.
Sounds like you are going through your own code waaay too often, for the purpose of changing the angle of each layer. You win when you let CA do the work.
So the strategy here is to find a way to have CA do the work, and call you back less than 50 times a second.
How about a CAAnimationGroup containing a few CAPropertyAnimation for each of your layers and setting up, say, one second of animation at a time?
Once you hand that off to CA, CA will playing it back in its own thread.
My advice is to go OpenGL ES.
Although Core Animation is a tad snappier than "UITransformations", the problem you're facing is a classic one: you're trying to create frame to frame based action with lots of "virtual" sprites floating around. That is not what UIKit is meant to be used for. Especially the animations you're trying to do. Rotation requires trigonometry in order to calculate pixel interpolation. That's quite an expensive procedure.
Unless there are clear restrictions to the intensitivity of the animation, the number of objects animation at the same time, and the frequency of recalculating new transformations, my only advice for you at this point is OpenGL ES.
My experience thus far with the iPhone has been quite alike. Every time we juiced up the app, the current platform could not handle it. We ended up using OpenGL ES, and it's worth the learning curve. The performance is incredible.
I'm sorry for the "bad news", but I strongly advise against using UIKit and Core Animation for frame to frame based apps.
It sounds like your redrawing your views constantly. I'm sure there is a way to disable this and only redraw at the end of the animation.