aspect2d objects on top

Hi everyone,

Does anybody know a way to have one aspect2d object on top of all others? I tried clearing depth write and setting the bin to ‘fixed’, and setting the Y of my object, which both didn’t help much.

I’ve had this issue too. Here’s how I solved it. You need to call “.reparentTo(aspect2d)” again on the node you want on top. The most recent .reparentTo(aspect2d) always goes on top of the other objects.

I realize that the objects are already parented to aspect2d. That doesn’t matter, just call the function again.

Thank you, that works fine as a temporary solution! Though I’d appreciate it if there would be a better way to do ZOrdering (or YOrdering :wink: ), since every time I create a 2d object I need to re-reparent the objects that need to be on top.

There is a better answer.

One answer is to call:

node.reparentTo(aspect2d, 10)

or some variant. The extra optional parameter indicates the sort value. Nodes are sorted within their parent in the order by their sort value; the default sort value is 0. Nodes that all have the same sort value are sorted in order they were added to their parent; this is why calling node.reparentTo(aspect2d) moves a node to the end of the list.

That gives you control over the ordering within the scene graph, which implicitly gives you control over the render order, since aspect2d is by default in the ‘unsorted’ bit, which really means its children are rendered in scene graph order. But you can use the setBin() method to give you explicit control over the render order, without having to rely on the scene graph order.

print CullBinManager.getGlobalPtr()

displays the current set of bins, and the order in which they are rendered with respect to each other. Note that ‘unsorted’ is drawn after ‘fixed’, which is why putting nodes in the ‘fixed’ bin does not move them to the top. But there is another bin drawn after ‘fixed’: the bin ‘gui-popup’, which was created for precisely this purpose. So you can put your toplevel geometry in the ‘gui-popup’ bin and it will appear on top of other 2d geometry.

The ‘gui-popup’ bin is also type unsorted, so if you want to place something on top of another object already in the gui-popup bin, you have to play games with the scene graph order again. Or, you can define another bin which sorts after gui-popup, and maybe this time give it type fixed, which allows you to have endless control over the render order within the bin (but forces you to think about the render order with each object).


Thanks a lot for this detailed explaination David, both methods solved my problem entirely.