Why another list?

As I was quite happy, that I almost solved this challenge exactly like the solution I still wonder: why is there a need for the actionButtonUIList? All available buttons are already in actionButtonContainerTransform.

My UpdateSelectedVisual() looks like this:

private void UpdateSelectedVisual()
    {
        foreach(Transform buttonTransform in actionButtonContainerTransform)
        {
            ActionButtonUI actionButtonUI = buttonTransform.GetComponent<ActionButtonUI>();
            actionButtonUI.UpdateSelectedVisual();
        }
    }

A new list prevents us from continuously calling GetComponent. In addition, we are the ones creating the buttons, so rather than giving it to something else and asking that something to give it back each time we want it, we just keep a reference to it ourselves. In the end, it will just be a tiny bit more performant when we execute it.

1 Like

Ah, okay. Thanks for the explination! :+1: I guess, I keep my solution. The performance loss must be minimal and shouldn’t have much influence on such type of game.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms