- Home /
passing objects to a method
Is it bad practice to use GameObjects rather than Transforms as parameters?
Answer by Bunny83 · May 16, 2011 at 01:48 PM
It actually doesn't matter ;). You should always pass the object that you need. If you just need the transform pass it. If you just need one of your custom scripts pass this. If you need multiple components in your method the most convenient way would be to pass just a GameObject and get the components in your method. You can also get the components outside and pass multiple references, but that depends on the function of your method and if it makes sence. If you allow to pass components seperate you can't be sure that those components belong to the same GameObject.
A single GameObject or Component reference makes no big difference since every Component have a reference to the containing GameObject (.gameObject
)
Answer by CHPedersen · May 16, 2011 at 08:09 AM
I think that depends on what the function you're passing it to needs it for. :P
Your answer
![](https://koobas.hobune.stream/wayback/20220613134359im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Correct way to spawn and move objects 1 Answer
How to Make a Transform Variable Target a Random GameObject? 1 Answer
Position gameObjects in circle around another gameObject 1 Answer
Game Object changed transform after Android App Bundle Build 1 Answer
Why GameObject.Find() work and parent.transform.Find() doesn't work? 1 Answer