Change zIndex for layering in cocos creator

I need to change the object layering dynamically at run time. Basically, I need to update the layer of the object so I can achieve layering like in Unity at runtime. We used Zindex to do that, but it is not working. Dynmically so any have example or simple project using zIndex or post share with me.

Which version of creator are you using?You can try to use setSiblingIndex instead of zIndex.

2.4.10 version .setSiblingIndex no i didn’t tried yet. if you have any examples please share with me.

Using z-index in CC is the same thing as re-ordering your nodes. It only works on sibling-nodes. It kind of makes sense, but I’ve always wished for a true 2D z-index feature that would override the node-order.

Can you please share any example cases for setSiblingIndex ?

You can refer to this example