- Home /
do static variables slow down framerates in iphone
I have approx 20 spheres (which are standard unity prefabs) that are bouncing about, created randomly and destroyed when colliding with a collider object.
Framerates are good except when I use scripts that utilize static variables. When using scripts that call var frm other scripts by using example:
somescript.somevariable Things get choppy.
Is there a better way? Is get component the most efficient for unityiphone 1.5.1?
Thx a bunch!
Answer by Ashkan_gc · Sep 03, 2010 at 01:03 PM
static variables just can limit memory and if they are not many (more than 10MB) they can not become a problem. the problem is about, how you get the reference to other objects and scripts. don't use thing like GameObject.Find and it's friends or GetComponent in Update and FixedUpdate. call them in Awake, Start or any other place that you will call just once to get the reference.
Answer by BoredKoi · Sep 03, 2010 at 12:45 PM
It would help to see the actual code in this situation. Static variables by themselves are not the problem I am guessing. GetComponent can kill framerates, however, inside an Update or (worse) FixedUpdate loop. You always want to cache those references for iPhone deployments like this:
private Rigidbody sphereRigidbody;
void Start() { sphereRigidbody = rigidbody; }
void FixedUpdate() { sphereRigidbody.doWhatever }
Your answer
Follow this Question
Related Questions
Can someone explain SendMessage to me? 3 Answers
'[insert member variable name]' is not a member of 'Object' / 'Component' / 'GameObject' 1 Answer
how can I create a variable to refer to any gameObject script with pragma strict 1 Answer
Global counter 0 Answers
How to make a loading screen? 2 Answers