sprite kit swift initial slow frame rate/ lag? - swift

I've just started learning how to use sprite kit, I've almost completed my first game, however I have come across a problem which I don't really know how to solve, basically when I first load the game/scene the game is very laggy FPS drops to about 30, and movement and animations are not smooth, however soon as the first scene is finished and play again everything is super smooth? so initial load is slow, second and every load after that is fine, I need some pointing in the direction, thanks

Related

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.

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

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.

Spritekit FPS drops when presenting UIView

I am finishing one of my project, a game made with Spritekit.
I created a small menu with UIKit (1 view and few buttons).
I connected SKScene and View Controller class to communicate so when game is finished, I am able to present menu.
I noticed problems with SKScene FPS.
I already found some informations from 2015, on apple developer forum that this problem was spotted with iOS 9 for the first time.
When I'm presenting UIView over SKScene, my FPS falls from 60 to 40.
And after I hide UIView and run game again, FPS increases back.. But in about 2-3 seconds, what gives me a lag in my animations on start of the game.
I tried with preloding all texture atlases first and nothing changed.
Than I tought my textures are too big and problem is in my animations, and I decreased all images and its quality from 32bit colors to 16... But problem was not solved.
Then I also noticed that FPS is worse, if I animate UIView..
So there is definetly problem with combining SpriteKit and UIKit.
I could pause scene before presenting UIView and unpause second or two after my view disappear again, and yeah maybe users wouldn't notice problem..
But what if I want to run my Scene in background of my UIView (like endless scrolling backgrouns), so background would move constantly when user enter menu?
I know, I could do the menu with SpriteKit, but this approach seemed to work fine 2 years ago when I was last time using SpriteKit.
Okay.. I am posting an answer, if somebody else is searching a solution for similar FPS problems.
After your comments and recommendations what to do, I tried few different things and figured out some problems.
I tested it on two physical devices iPhone 6S and iPad 2. Of course results on iPad 2 are a bit worse.
UIKit and SpriteKit are surely not working best together.
I figured out that there are no big problems with just presenting other UIViews or UIButtons over SpriteKit scene - FPS drops a bit but not really much, that this would make some big impact on your scene (2-3 FPS).
Biggest problems came in if you're trying to animate Views with some basic animations. In that case FPS (in time that animation is happening) drops to 40 - 35 FPS, and the biggest problem with this is, that sometime it just wont raise again until you make another animation or run scene again.
I still don't know why this is happening, but it happens randomly. Sometimes FPS raises and sometimes not.
Another thing that also have big impact on SpriteKit frame rate are Ads if you're using them.
I am using AdMobs and in their documentation it's well written, that Banners or Interstitial Ads can make impact on your frame rate. I am not presenting Ads during gameplay, but also if you're presenting them in menu, this will decrease your FPS and when you run your game and your FPS drops again for a bit, the result will be even worse.
So I suggest you run your Scene with delay or hide banner a bit earlier so it won't have impact on your start of the game.
I found solution for my problem with pausing the scene as soon as gameplay ends, so when menu appear my Scene is on pause mode. And after I run my game again I am un-pausing my Scene. It's not the best solution for my case, but it works much better now.
I suggest to use SpriteKit also for your menu creation, this way you won't have such problems. Or even better - use some other game engine for your game creation.

Unity 3D low fps

I'm using Unity3D 5.3 version. I'm working on a 2D "Endless running" game. It's working normally on PC. But when I compile it to my phone, all of my gameobjects are shaking when they are moving. Gameobjects are in a respawn loop. I'm increasing my Camera's transform position x. So when my camera is in action, all of the other objects look like they are shaking a lot and my game is working slowly on my phone as a result. I tried to play my game at Samsung, on discovery phones. It's working normally on some of them. But even on some Samsung devices it's still shaking. So i don't understand what the problem is. Can you help me with this?
One thing you can do is start optimising, if you have a game that is either finished or close to it. If you open the profiler, click "Deep Profile" and then run it in the editor on your PC, you'll get a very detailed breakdown of what is using the most resources within your game. Generally it's something like draw calls or the physics engine doing unnecessary work.
Another thing that might help is to use Time.deltaTime, if you aren't already. If the script that increases the transform doesn't multiply the increase by Time.deltaTime, then you're moving your camera by an amount per frame rather than per second, which means that if you have any framerate drops for any reason, the camera will move a smaller distance and that could be throwing out some of your other calculations. Using Time.deltaTime won't improve your framerate, but it will make your game framerate independant, which is very important.

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.