- Home /
Question by
epicdev1 · Apr 04, 2018 at 05:53 AM ·
variablestagsperformance optimizationcache
What is going on behind public variables that I assign in editor?
Which one is good on performance?
public Rigidbody rb;
public GameObject player;
//assign in the editor
vs
Rigidbody rb;
GameObject player;
string playertag = "Player";
Awake()
{
player = GameObject.FindGameObjectWithTag(playertag);
rb = player.GetComponent<Rigidbody>();
}
Comment
Answer by losingisfun · Apr 04, 2018 at 06:31 AM
Assigning a variable in the inspector is much better than using GetComponent (avoid using GetComponent if you don't need it, it's a fairly costly method of getting components)
Your answer
![](https://koobas.hobune.stream/wayback/20220612160019im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how to set public variable to a tag unity 1 Answer
Let's Discuss Efficiency (Tags Vs Variables) 1 Answer
What is better: Set a animator variable each frame or use a if to check if need? 2 Answers
Reference other scrips in prefab 1 Answer
Disabling GameObjects With A Tag That Are More Than A Set Distance From A GameObject? 2 Answers