Currently, I’m trying to create a game in swift’s SpriteKit, and I’m trying to give it a smoother framerate than it has currently. Right now, whenever I, say, press a button, the framerate suddenly jumps to a much lower value, causing the player sprite (whose movement is based on a value multiplied by a deltaTime value) to suddenly jump forward. Is there any way to smooth the framerate such that the changes in framerate aren’t so sudden and drastic?
Code running in the simulator isn't a good test of the graphics performance of a Sprite-Kit (or Scene Kit) application.
This is because SK will, in order to perform certain graphics effects, utilise calls to the specific graphics hardware available in an iOS device whereas in the simulator, these calls will need to be emulated in software by the host machine, causing a reduction in graphics performance (some operations will be affected a lot, other less so), even if the underlying graphics card in the host machine is nominally more powerful that the one in the iOS device.
Simulator testing is good for testing functionality, and it can give an indication of performance. For example, an application that was running OK in the simulator suddenly starts performing poorly after a change. Checking the displayed 'draw count' shows that the number of 'draws' required to render the scene has increased, possibly causing the slowdown. Or conversely, a change may lead to an increase in performance and a reduction in draw count.
However, the only way to be sure is to test the application of a real device.
Related
I have a problem on some Android devices with the particle system's rendering (weirdly enough the problem seems occur on devices with higher capabilities). The problem occurs when mesh based particles (Renderer/Renderer Mode/Mesh) are being rendered. It seems like the meshes that are being spewed out and slowly shrunk with time are being reduced ("reverse-tessellated") which results in a nasty visual effect. Does anyone know what might be the cause of this?
UPDATE: One thing that I've noticed is that with time - the longer the gameplay - this problem is getting worse.
UPDATE: What I've tried is to make one particle system bigger (around x5 times) in order to check if it will have any effect on it's rasterization. Normally particles are sized down from 1 to 0 based on their life-time. What I've noticed, after sizing them up, is that the problem does not occur anymore.
UPDATE: Visualisation of the problem:
Properly rendered:
Improperly rendered:
I was able to track the issue down. It turned out to be a problem within a toon shader I wrote while a go. All the things I've noticed are valid but unfortunately it took some time to put me on the right track.
Taken from Unity's documentation
The half and fixed types only become relevant when targeting mobile
GPUs, where these types primarily exist for power (and sometimes
performance) constraints. Keep in mind that you need to test your
shaders on mobile to see whether or not you are running into
precision/numerical issues.
Unfortunately for me, as it cost me quite some time, I've used half3/4 values with POSITION semantics which caused some numerical precision issues on some Android devices (in this case the particles were getting smaller and smaller - size 0 to be exact). As a general rule, from what I've read in Unity's documentation, float3/4 should always be preferred in conjunction with POSITION semantics.
My daydream app is working fine when used slowly. But when I rotate my head too quick it starts giving glitches first and then the app gets crashed. I am guessing it has to do something with frames/sec loaded during high quality objects rendering or something similar. If someone has a solution, please help me out.
Assuming you have no errors in logcat, visual glitches are generally indicative of extremely high per frame GPU load.
It would be good to profile your app and share the crash report - but the only way I've ever been able to actually crash an app this way is with very large textures.
Check the size and number of textures in your scene - it's possible rapid head rotation could be causing a large number of textures to need to be loaded as objects become visible. You can also see a good list of how large the assets are at build time in Unity by inspecting the editor log after a build. This can help make sure you aren't running out of RAM on device.
Make sure you have texture compression and mipmaps enabled on all textures. Disabling mip-maps on minified textures can easily overload the GPU.
Make sure you don't have too much transparency. Adding a lot of overdraw to the scene can overload the GPU.
Follow performance optimization guidelines https://docs.unity3d.com/Manual/OptimizingGraphicsPerformance.html
https://unity3d.com/learn/tutorials/topics/virtual-reality/optimisation-vr-unity
Make sure renderViewportScale is around 0.7, MSAA is at 2x or less, and you aren't using post-process effects, shadows, or any kind of deferred rendering
Stay below 100 draw calls, 200k vertices on screen.
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.
I'm making maps for my game. I designed forest for map by using many tree, stone.. Images (insert image into unity scene and arrange it). My game runs well on Android but can not run on iOS (ip4s). It met memory problem. I want to ask everyone:
If i design the forest in photoshop instead of unity, is that way better than my current way?
Thanks all
It depends on what you are trying to do.
But anyway, there is a common way to solve memory usage related problems. Fire up the Profiler!
http://docs.unity3d.com/Manual/Profiler.html
There you can see what is eating your precious memory. So you can try and decide if it's best to make them combined in one image or keep them as separate images. Maybe you would also see the memory problem could be related to other assets you use.
You need to look at Instruments in XCode. Also you can use the Profiler that comes with Unity. Another way you can save memory is by reducing the graphics strain on the screen. You need to see your draw calls and verts, and tris under stats. Keep draw calls under 50-60. And keep verts and tris down. Look at the graphics benchmarks for Graphics on OpenGL, iPhone 4S is an older device and depending on your android may be substantially slower. iPhone 4S has 512MB of RAM I think. This should be enough to handle a pretty big memory load. Check out your OnGUI() objects and calls. You want to mitigate those as much as possible. Also try and use culling to your advantage! Also if you are using Fog or camera filters they take a substantial load as well too. Stay away from Literal Types, too if you can.
Also use Vertex Lit for rendering path vs forward rendering path. Use auto best performance for resolution, too. This will make everything go at 0.75 resolution instead of full retina 960x640 or whatever it is for 4S. You can also in Xcode tweak the resolution, depending on the size of your controls you could make it 0.6
under DeviceSettings.mm in your XCode Project:
case deviceiPhone4S: resMult = 0.6f; break;
or in your MonoDevelop UnityScript (depending on orientation):
Screen.SetResolution (Screen.width * 0.6f, Screen.height * 0.6f, true);
I'm wondering about providing an user selected option to lower the framerate in my opengl based game to conserve battery life, and in general detect parts of the game where no movement occurs and lower the framerate there as well (when saying framerate I actually mean the number of times per second the entire screen is redrawn using opengl commands)
The opengl app is made pretty much the same way as the opengl template that comes with xcode.
Did anyone check if this has any significant impact on battery life?
Sure framerate have impact on battery life. It need cpu/gpu cycles to render each frame. But how much impact on battery life depends on what are you rendering. Btw, you might want to give users ability to dimmer the backlight as well (that have impact too, huge).