I have a UI image in the new UI system, it’s the child of a canvas with several other UI elements (buttons, images, text). I have an image residing at the “back”, and I want to move it to the “front” programmatically.
Image img = GetComponent<Image>();
img.z = 1000;
This code obviously doesn’t work, and I’m having one hell of a time finding a solution that isn’t “drag it lower in the hierarchy”.
There should be a dead simple straight forward single function call answer, and I can’t find it.
If your canvas is screen space - overlay, child elements are rendered from top to bottom, so lower elements are rendered last - on top of previous. Simply set it as last transform.
I think you have the SetSiblingIndex variable wrong.
SetSiblingIndex(0) will move the element to the top of the Heirachy which will put it behind all other elements. SetSiblingIndex(10000) will force it to the bottom as long as there are not more than 10000 elements in your heirachy. Being at the bottom of the Heirachy will force it to the front of the display.