I'm making my first game with Swift and SpriteKit and have noticed that my game quickly approaches 100% CPU use. I have been posting a lot about this recently, but here I'm now I'm now attempting to pull it apart to determine where my problems are. I originally thought my problem was with instantiating new enemies, so I removed everything but the small user-controlled spaceship and its shooting functionality. However, I'm still hitting 100% after a couple minutes of "play". I'm using the time-profiler instrument to try and figure out whats going on but I'm having trouble. I've broken up the time line:
Here is the first subgraph when the user clicks a homeScene button to enter the GameScene.
I'm not entirely sure what the red and yellow "Heaviest backtraces" with 3256x and 861x respectively mean, but from tutorials I've seen I would imagine that they are abnormally high. Here is the Call Tree as well:
I'm also not entirely sure why the controller textures would be using so much as they are simply setting two textures in the file right before the GameScene class:
let controllerBaseTexture = SKTextureAtlas(named:"Sprites").textureNamed("controllerBase")
let controllerHandleTexture = SKTextureAtlas(named:"Sprites").textureNamed("controllerHandle")
class GameScene: SKScene, SKPhysicsContactDelegate {
Then here is the Call Tree when the game starts and when the CPU reaches 100%:
I'm also confused about what "UnsaveMutableAddressors" are, as I see them very commonly when trying to debug this code.
I know this is a lot, but I'm not sure where to begin. Any suggestions would be awesome. I would also like to know if there are good resources on how to interpret this better because I've gone through a handful and I'm still very stuck.
Thanks for any help!
The profiler shows it's something in your update method for your gameScene. Keep in mind this gets ran around 60 times per second so you don't want to do anything extremely heavy there.
Related
Im optimizing my game for mobile. For that reason a low amount of batches is important. By using Frame Debug I found out that for some reason the Draw Mesh Node command is performed for every single node eventhough the nodes are static and have the same material as far as I understand. The frame debugger says that the objects cannot be batches because the "Objects have different materials". I dont get why and how to fix that. The nodes are all based on a prefab of them. The only thing that is different between them is their position. Please help
The Frame Debug Window:
Prefab for every node:
Example for one of the nodes in game (ONLY their position is different):
Problem solved after 2 days of being sad and watching every graphic performance tutorital on youtube.
Basically I needed to change every .material code to .sharedMaterial because for some to me unknown reason unity creates a copy of the material when using .material, after which each node got its own material. For that reason the performance was so bad. Now it works and my live quality has increased, since everything gets batched, reducing the draw calls from 300 to 10 :)
I hope future readers are helped by this!
I am testing on a little car game using Apple's SceneKit, to simulate the car behavior I'm using SCNPhysicsVehicle class.
For the first development steps I drove the car on a big area. This worked fine. I've set up all the car variables so that it felt like expected.
In the next step I wanted to build the road. Naturally the road should consist of parts so I can create different racing tracks.
Here is where the trouble begins.
I just made a straight road consisting of 50 blocks. The blocks line up a 100% perfect.
Anyway the car bumps and "jumps" in every place where two road blocks meet.
For better understanding I made a Video showing the wired behavior.
Did anyone ran in the same issue? What I'm doing wrong?
Any thoughts or suggestions would be appreciated.
I'm currently trying to develop a little game on Apple Watch using SceneKit.
This is a simple 2D game, with geometric shapes I tesselate.
Here is my problem. I use SCNAction to move my objects across the scene, and I don't know why, but even if the SCNScene showStatistics show me the scene runs at 60 FPS and I can see that the CPU does very little, every SCNAction is updated every half-second or so.
It's very annoying because my animations aren't smooth at all and it hurts gameplay.
Does anyone already had had this kind of problem? I've spent too much time trying to find where something went wrong and I can't find it. Is there some kind of refresh rate property on SCNAction?
Thank you in advance for the time you'll give to my case. :)
I'm trying to load a scene asynchronously so I can have a nice progress bar and I found that the returned AsyncOperation.progress stops at 0.9. I don't have a problem with that but what is happening is that after that, it takes up to 50s to load the scene and that doesn't show on the progress. After deleting some objects I found that there is 1 (the main scene object) that is causing this delay.
My question is, is there any way to load this object in the first 90% of the load (which is happening super fast right now - 1s)?
Thanks in advance
If this GameObject is inside the scene, it is loaded with the scene. The problem you have is with the all script logic inside the scene. The loading thread actually finished, but the scripts, instantieting etc., takes all device resources and it looks like stuck at 90%.
To solve it I think you should delay all scripts executions on Awake or Start methods. That should help, but still all the time needed on particular device to execute scripts will take all CPU, and will look like stuck again.
So, it seems it all comes to the substances I was using. It's really strange for me because I explicity check all of them as "bake and discard substance" which seems to do nothing. After baking all the textures and switch from substance to texture in the material the loading came down from 42s to 1s
Our first game is about to go live. We have found that the performance of sprite kit is reasonably good. We are moving hundreds of sprites around and have effect nodes and sounds. However you must not dare to set the score. The SKLabelNode is very slow.
after running diagnostics it was found that the following code was the culprit.
scoreLabel.text = [NSString stringWithFormat:#"Score: %d",my_score];
In the diagnostic tool the setText command was showing as the most expensive. We even made sure that it was not being called that often. It still resulted in a lag causing the sprites to jerk/jitter/hickup. Once we removed the line...we got smooth motion.
If we are not able to use the SKLabelNodes inside the game scene, what other options are there?
Be careful you aren't loading the entire font family.
If I load "Chalkboard SE" it will take 4-6 seconds, and appear to work.
But if I load ChalkboardSE-Regular , it's virtually instantaneous ~100ms or less.
Once it's added to the scene, subsequent calls are very quick. But if you transition to another scene, it might re-load, so do it early.
I did some testing with font families first, and the results are pretty catastrophic. Caching strong references doesn't help. https://gilesey.wordpress.com/2015/01/14/ios-spritekit-font-loading-times-of-sklabelnodes/