#Performance of .transform call?

1 messages · Page 1 of 1 (latest)

versed patrol
#

Should .transform calls be stored into a variable?
What is the performance difference of calling myObject.transform lots of times, as opposed to doing this:
private Transform myTransform;
myTransform = myObject.transform;
This way .transform is only called once. and then myTransform is accessed lots of times.
Which is better and what is the performance difference?

remote stirrup
#

Absolutely! If you're calling myObject.transform a bunch of times, it's usually smarter to grab it once and reuse it. A call to the property results in going across our bindings layer and into C++ to extract the transform and return it, so doing this once instead of every time is advisable. As for the performance difference its hard to give a figure, I would suggest trying the profiler with 2 versions, 1 with a cached transform and one without and see what difference you get