|
Hello UA people. My frame rate isn't particularly low at the moment, but i am exporting to flash so want to optimize it as much as i possibly can. Profiler is indicating that the below script is at 39.8% not sure exactly what these figures mean, but it surely can't be good. Can anyone recommend alterations to this script that would be more efficient? It should be pretty straight forward to you guys, but if anything is unclear i'll happily explain. I realise there is a lot in the update, but as far as i can figure there isn't any other way, but i'm sure i'm wrong! haha. Cheers guys!
(comments are locked)
|
|
you aren't doing anything in an outrageously silly way. However, a couple of tips that might help: 1) use enums instead of strings to hold your state variable. E.G. 2) You should delegate the bullet destroying behaviour at the end of your shootStuff() method to the bullet itself. E.G create a new Script DestroyAfterDelay.js and attach it to your bullet prefab. In DestroyAfterDelay.js have: or something along those lines
(comments are locked)
|
|
Use this just change the frameRate variable to whatever you want Source: http://unity3d.com/support/documentation/ScriptReference/Application-targetFrameRate.html EDIT if you go Edit > Project Settings > Time it will give you three options: Fixed Timestep Maximum Allowed Timestep Time Scale the fixed timestep will allow you to control the framerate and the maximum allowed timestep will allow you to set the maximum framerate. Hope it helps Surely Unity should just do this automatically? why wouldn't it want to supply the best possible frame rate?
Apr 10 '12 at 01:16 AM
TheFrankman123
Besides, i'm more looking at how i can re-write the code itself more efficiently, since i'm sure this is a bit of a dirty way to do it.
Apr 10 '12 at 01:40 AM
TheFrankman123
oh I see what you mean
Apr 10 '12 at 01:48 AM
Aydan
read through this see if you can find anything useful http://answers.unity3d.com/questions/37293/general-ways-to-optimize-frame-rate.html
Apr 10 '12 at 01:53 AM
Aydan
The default value for Application.targetFrameRate is -1, which means "as fast as possible". Setting it to 300 is basically useless...it doesn't mean it somehow forces Unity to run at 300 fps, which is of course impossible.
Apr 10 '12 at 02:50 AM
Eric5h5
(comments are locked)
|
|
You might try deep profiling. It'll slow down your game while it's active, but it also provides a lot more information, specifically including nested function calls, which makes it much more useful for identifying hotspots. Beyond that, I notice two things: Calling Looks like you're calling Otherwise, I didn't notice anything obviously amiss, but it's easy to overlook problems. My main advice is still to check out deep profiling, and look for functions which seem to take more time than they ought to. Thank you Rutter. This was the kind of answer i was looking for. I wont accept the answer just yet, see if anyone else notices anything. Thanks for point out the debug, i kind of assumed that when you built the game it would ignore the debug since it doesn't actually show up anyway. Also, thinking about it, not sure i even need the wait for seconds anymore... Cheers!
Apr 10 '12 at 02:45 AM
TheFrankman123
using WaitForSeconds() with a yield statement does not block execution of the update loop. Unity JS automatically turns any functions with yield in them into coroutines, and wraps the function calls in StartCoroutine(), so the shootSutff() call is actually equivalent to StartCoroutine(shootStuff()).
Apr 10 '12 at 03:23 AM
simonmc
I see. Thanks for the explanation. I'm far more used to C# coding, and sometimes it shows a bit painfully. ;)
Apr 10 '12 at 06:01 PM
rutter
(comments are locked)
|
