- Home /
Assigning unchanged position to transform
This question involves internal optimizations of Unity.
Supposing I do something like this:
Vector3 v = transform.position;
v.x = Mathf.Repeat (32f + v.x, 64f) - 32f;
v.y = Mathf.Repeat (32f + v.y, 64f) - 32f;
transform.position = v;
My question is whether Unity is smart enough to realize that in some cases, the position will not have changed, and not do any extra work (e.g. updating physics collision data) in those cases.
Or, if it will always perform the assignment and any extra work without checking for actual changes (in which case it might make sense for me to add such checks myself).
Basically, I'm wondering if this is the best way to implement a wraparound script (to place on objects to let them wrap the screen), or whether it's better to have if statements to only assign position in case it actually changed.
I believe that assigning to transform.position does not update physics/collision data in all cases, even if the position has changed.
Your answer
Follow this Question
Related Questions
Simple animations - hardcoded or import animation 1 Answer
How to use transform.position? 2 Answers
How can I defer the recalculation of child transforms whilst modifying the parent transform? 0 Answers
Keeping an Object Locked In Position Around Another 1 Answer
why is transform.position giving me local location?(c#) 0 Answers