This is so trivial yet so infurtiating that I have no idea how to progress with it. So I have counters next to my functional buttons in the game, which should go down every time they’re used. So here they are in hierarchy of my GUI. I also have some code attached in my “game brain” script which handles the initial values (let’s not bother with the changes):
void Start() {
...
changeCounter(pollNewColours_obj, pollNewColours_counter);
changeCounter(swapColours_obj, swapColours_counter);
...
}
...
private void changeCounter(GameObject obj, int newValue)
{
obj.gameObject.GetComponentInChildren<TextMeshProUGUI>().SetText(newValue.ToString());
}
And finally, we have the respective objects and counters attached in the brain (don’t worry about there being both a reference to the top-level object and the counter itself, it’s just because I’ve tried a lot of combinations to make this work so there are some redundant leftovers).
Yet when we run it, instead of getting a 1 on the top button and a 3 on the bottom one, we get them reversed. And if we keep playing, they’re gonna decrement correctly - but on the wrong buttons.
Why on earth is that happening? I’ve tried accessing the .text and using SetText(), I’ve tried going form the top level object and finding the TMP objects through GetComponentInChildren<> and through accessing the component directly, I’ve even tried putting these into the Update() to be sure nothing overwrites them between the Start() and later methods - all to no avail. No matter what I do, they’re always reversed.
Any help will be greatly appreciated.