- Home /
What's a cheaper reference, GameObject or Transform?
Hi guys, I'm just wondering what is cheaper to do, if there is even a speed difference at all. Say I'm making an array so that I can loop through it and modify SetActive on each one. Is it cheaper to have an array of Transforms and do xxxx.gameObject.SetActive(xxxx) or is it the equivalence of efficiency or better to stick to an array of GameObjects for the usual xxxx.SetActive(xxxx)? Sorry it's not a super serious question, I just had to ask because I lack the knowledge figure it out :P
Answer by ShadyProductions · Jun 12, 2018 at 06:44 AM
It's actually impossible to determine exactly how much memory a gameobject takes in Unity, I've done several tests with them and I've noticed that most of the times a game object takes roughly 300bytes (empty gameobjects with a transform). It really doesn't matter if you take transform or gameobject, the memory get's reused anyway by new gameobjects.
Answer by camander321 · Apr 02, 2019 at 08:26 PM
As far as I'm aware, if you're looping through an array of gameobject references, its really just an array of memory addresses either way. Might as well just keep track of the gameobjects if you dont need the transforms for anything.
Your answer
Follow this Question
Related Questions
Are .gameObject and .transform both using GetComponent() in the background? 1 Answer
Calling gameobject.transform vs. just calling transform directly - Performance negligible? 1 Answer
How can I defer the recalculation of child transforms whilst modifying the parent transform? 0 Answers
Translate.transform problems (collision/Rigibody) 0 Answers
NaN exception when spawning soldiers 1 Answer