Efficiency between getcomponent<> and save reference in a variable
I believe the title may be quite explicative.
In my case I need to manage many different components (a bit more than shown below) attached to some UI elements.
I'm wondering if it's more efficient to store all the references in variables, or I can just get all the components each time I click on a botton.
This project is meant to be built in WebGL. Actual project I'm working on In the code below the method FillPanel populate a panel with descriptions, images and transition effects (not present in the version at the link)
void Start()
{
panelUI = new GameObject[gameObject.GetComponentsInChildren<Transform>().Length];
for (int i=0; i< gameObject.GetComponentsInChildren<Transform>().Length; i++)
{panelUI[i] = gameObject.GetComponentsInChildren<Transform>()[i].gameObject;}
// panelUI[0] : Panel
// panelUI[1] : Title
// panelUI[2] : ScrollView
// panelUI[3] : Viewport
// panelUI[4] : Description
// panelUI[5] : Image
// panelUI[6] : ScrollBar
// panelUI[7] : Handle
}
void FillPanel(bool Component, string element)
{
panelUI[1].GetComponent<TextMeshProUGUI>().text = element;
panelUI[2].GetComponent<RectTransform>().offsetMax = new Vector2(-5f, -10 - panelUI[1].GetComponent<RectTransform>().rect.height);
panelUI[4].GetComponent<TextMeshProUGUI>().text = oT.Livelli[element];
}
Your answer
Follow this Question
Related Questions
Different pc performance problem 0 Answers
Unity | Mac | Webgl | Retina | Inconsistent performance 0 Answers
Web GL game performance drop while hosting 0 Answers
Getting errors while trying to build for WebGL 0 Answers
Trigger to open URL in a new tab works in Unity but not WebGL Embed. What's the fix? 0 Answers