- Home /
Calling gameobject.transform vs. just calling transform directly - Performance negligible?
Hey Everyone, In my game, I have empty gameobjects that represent targets for characters to move to. I store those objects as GameObjects, but I pretty much always use them as gameObject.transform. I know there is a performance hit, but I was wondering if it's negligible, or if digging down in a gameObject into its transform actually hurts performance enough where I should go through my game to change all of those to transforms. And I am at the point where I am trying to optimize, and I've already optimized the biggies.
Anyways, I know the question is subjective (does my game perform well already/might not be worth it), but it's something I've always been curious about anyways. I appreciate it.
Thanks!
The only real difference is with gameobject.transform you're accessing the gamobjects Transform ins$$anonymous$$d of calling it directly. A Transform is what defines the object's location, they're almost identical in performance but I've never checked the cost difference in the two. I don't even think it's worth trying to optimize but if you do find a major difference please post what you find.
Ok, thanks for the response. I will definitely update the thread if I find something interesting!
Answer by brunocoimbra · Oct 27, 2017 at 10:31 PM
The difference is so, but so small, that there is no real reason to optimize it.
Cool, thanks. That's what I thought, but I wanted to ask some other people for their thoughts.
Your answer
Follow this Question
Related Questions
Are .gameObject and .transform both using GetComponent() in the background? 1 Answer
Assigning to global transforms of current gameobject 1 Answer
Detect 2D GameObjects when "Colliding" with each other without RB and collider. 1 Answer
Unity Best Practices - Cached Components 1 Answer
Transform vs Gameobject 3 Answers