I have added an image into a button and is now trying to change that sprite and have problem to grab it.
newItem is a GameObject as i create the Button’s dynamically.
Button
Text
Image <<< Added this to the button
I am trying to do it with: newItem.GetComponentInChildren<Image>().sprite = sprt_twoPlayer;
but can’t actually grab the actual image, i get the button background. The result is that the button native image is change meaning that the background get’s the sprite. I want my little added image to get the sprite.
That should work I just tested it myself. I’m not sure if you are repeatedly doing this, if so I suggest you cache the Image reference and the button so you can edit their properties without having to waste CPU time, its small CPU usage but try to save where you can so your game can run as smooth as possible.