I know ZIndex goes up to +2B, but I have a lot of GUI elements in a game, and I want to be able to render a GUI under all others if possible. Problem is that a lot of ZIndexes of GUIs are set to 1. 1 is the default. I don’t want to go through the hassle of changing all ZIndexes or having to run code in the command bar just to layer this particular GUI underneath.
Of course, I could go on changing like 40 or 50 ZIndexes, and what happens if I had to make a GUI that renders underneath that particular GUI? I’d have to do it again. Letting ZIndex go at 0 or -1 or even under that (-2B) would be nice.
As a temporary fix you can always run a quick command in the command bar using GetDescendants which raises every ZIndex by some amount. Real simple and will take under a minute rather than going through every gui object you have and changing it manually.
When ZIndexBehavior.Sibling is enabled, we’ll need negative ZIndex values to avoid having to awkwardly restructure our UI hierarchy. For example, I want an image border behind a button: Ideally I would create the image, parent it to the button, and then set its ZIndex to -1 so it would layer under the button even though ZIndexBehavior.Sibling is enabled.
With ZIndex values constrained to > 0, I would have to parent the button to its own border so all code becomes root.border.button instead of root.button – this is unwanted because logically a border is an attribute of a button (it doesn’t make sense the other way around), and it bloats the references to the button instance.
While we’re at it, is there any reason why ZIndex can’t be changed to a float?
This a totally different feature, and conflicts with the OP. Changing the order in relation to the parent when the ZIndex goes negative would be counterproductive to solving the posed problem. OP basically wants the ZIndex to default to the middle of the ZIndex space, rather than the bottom.
Your request would work better as a new ZIndexBehavior, one which causes the parent to be involved in the ordering. It wouldn’t make sense with Sibling, since the parent is not a sibling.
Setting a negative ZIndex would not help you in this case, unfortunately. Sibling doesn’t work like that. You may be thinking of the way CSS does it, which is where each node has a Z depth based on its depth in the hierarchy, and then the ZIndex property is a relative offset to that value. I just put the button inside its border, generally.
ZIndex clamping is now disabled on production. Negative ZIndexes are allowed. You can now use them to force an element to render underneath its siblings, for example. It will not allow you to render an element beneath its parent in Sibling mode, though.
The way that the Sibling mode works is that the ZIndex property controls the ordering relative to its siblings, not relative to some kind of global value. It wouldn’t really make sense with how its behavior is defined for it to work like you’re describing.
One advantage of this approach is that if you have two objects with children, and they are overlapping, one will render over top of the other’s children. This makes it so that you don’t get the “interlocked fingers” visual of the children rendering over top of both parents, instead of only over top of one.
Sorry to bump a post that’s a couple months old, but there should be a way to put a sibling behind its parent. I’m currently having to restructure my UIs just to put a background behind my ViewportFrames.