- Home /
are saved transforms quicker than .transform?
this is actually a general question in the sense that if i have a script for movement for example which is obviously a script that will use the transform/rigidbody components of the object there attached to. is it worthwhile to do
movement_transform = transform;
then later do
movement_transform.forward;
or is transform.forward just as fast?
it seems like finding the attached component MIGHT be an intensive process for unity (it seems a bit odd if so, i'd have imagine it'd almost just be a saved memory address, in which case it would be only VERY VERY slightly faster to go straight to it than grab the memory address first).
The thing is when i used a for loop to get something it appeared saving it and accessing it was ALOT faster than the alternative.
Based on that i'm actually fairly sure it is faster but if you know i'd also like to know why. Is retrieving the memory address really that intensive?
Answer by liamcary · Mar 04, 2013 at 05:47 AM
Yes it is. I did a quick performance test sometime last year just by accessing the transform ~1000 times and comparing times. Storing the transform is considerably faster but i'd only bother if you're accessing the transform every update or if there's a lot of instances of that object.
Answer by Owen-Reynolds · Mar 04, 2013 at 03:31 PM
Transform is just one of many co-equal components of the gameObject, stored in a list.
So cow.transform
finds the component list, initializes the search pointer and begins the loop. Then finds the 1st in the list (does a TypeOf on it?) and checks whether it's a Transform.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Destroying Components from Editor Script Throwing MissingReferenceException 1 Answer
How to import the object from server to unity 2 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer