- Home /
parent.parent.parent or FindObjectWithTag?
I'm wondering which one is faster, and possibly if anyone knows at what point which one would become slower.
The object my component is on that I want to get is tagged already so it is possible to get it through a tag, but in my head parent.parent.parent.getComponent would be faster, but I'm not sure. Even then the possibility of GetComponentInParent is still there.
Does anyone know definitively which one is faster?
Answer by Idual · 19 hours ago
My guess is the same as yours that it would be quicker to go through the hierarchy and then GetComponent<>().
My other thought is that if you are worried about the efficiency it's probably because you are doing this often. In that case, it would probably help if you can cache the result so you have it next time.
Answer by TobinCavanaugh123 · 9 hours ago
Accessing a variable will almost always be quicker than using a findobject, as such the parent.parent.parent would probably be quicker, but having a script or transform reference would be best
Your answer
Follow this Question
Related Questions
Connecting Multiple Rigidbodies with Collision 0 Answers
Access component of parent with multiple children 2 Answers
GetComponent() vs Delegate/Event 1 Answer
"GetComponentInParent" - How do I do it? 3 Answers
Talking To Other Scripts 1 Answer