Draworder of Spines and Sprites

Hey hey :slight_smile:

We are currently working on a game where we need sprites to be drawn on top of spine objects and we ran into this issue, that the spine was always drawn on top of the sprites. We looked at the source code of the spine plugin and found this part of code:

446  ...
447  for (i = 0; i < len; i++) {
448      this._meshes[i].name = batches[i].mat;
449      var mi = new pc.MeshInstance(this._node, this._meshes[i], this._materials[batches[i].mat]);
450      mi.drawOrder = i + (this.priority * 1000);
451      mi.visible = !this._hidden;
452      this._meshInstances.push(mi);
453  }
454  ...

In Line 450 the priority gets multiplied by 1000. We then tried setting the draw order of the overlapping sprite to 10.000 and it worked.

The thing is that this cost us quite some time to figure out, since we didn’t know if the layering of our object was wrong, or a different issue causes the problem. It would have been nice to have some description on the script attribute or something similar.

Also, I wanted to ask why this decision was made in the first place. Why should spine objects always be rendered on top of other objects, and not leave that decision to the developer?

It was probably originally written to have everything in the game to be a spine object rather than mix and match between all the possible renderable types.

Sprites weren’t added to the engine till after the spine runtime was originally written.

Given the number of possible meshes per spine object, 1000 probably seemed like a ‘good’ number when it was written.