2D Toolkit Forum
2D Toolkit => Support => Topic started by: arvz on February 06, 2014, 08:53:18 am
-
Hi,
I am following the Whack a Mole tutorial (http://www.unikronsoftware.com/2dtoolkit/docs/latest/tutorial/whack_a_mole/game_objects.html)
I'm doing this in Unity 4.3.x with Sorting Layers, so I'm sorting the sprites using 'Order in layer' rather than using z-values. When I click Commit on the static sprite batcher, the Sky Burst sprite moved itself on top of the landscape sprite, but if i hit Edit, then the sprite is fine again.
Does the static sprite batcher have a problem respecting layers? or did I do something wrong
Before Commit:
(http://i.imgur.com/o1Ta9zP.png)
And After Commit:
(http://i.imgur.com/ZbB8ROn.png)
-
It doesn't respect layers and for good reason. Sorting layers in Unity work globally, and while the batcher could wort within itself, it wouldn't be able to sort with the rest of the scene as sorting layers are stored in the renderer and the entire static batcher only has one renderer.
-
I see, thanks for that. Does this basically mean we must use z values?
-
Yes
-
Hi Unikron.
I am having the same problem, with the exception that I am already using z-values instead of 'order in layer'. Additionally I am setting up the sprite batcher via code at runtime, instead of setting it up beforehand in unity.
I got it working perfectly as long as there are no overlapping sprites, but in the case of overlapping sprites, the sprite batcher draws the first sprite encountered in the code on top, and every subsequent sprite is drawn under the last one, regardless of their z-value.
To position the batched sprites, i am using the function tk2dBatchedSprite.relativeMatrix.SetTRS() as indicated in the docs, in case it may have anything to do with it.
Been trying to solve this all day, with no success. Could you please help me out?
Thanks in advance.
-
The sorting is only performed in the editor - it makes sense for the GUI related stuff to give the same results before and after committing. If you're adding sprites at runtime, just add them in the order you want them drawn in.
-
What about having different static sprite batchers in different layers? Or in the same layer but in a different order? I don't see the option once I commit...
-
There isn't. Mainly because the sorting layer stuff isn't exposed properly in Unity. Easily added to this specific case though, as we've done the grunt work for the rest. How would you expect this to work when not committed though?
-
Ideally it should also respect layers when not committed. Is it doable? Once you assign a layer and layer order to a static sprite batcher all the children sprites should get this from the parent batcher when not commited.
Let me know if it can be done like this.
-
No that can't be done, the batcher reduces everything to one renderer, and unity layers are set per renderer. That is one of the reasons I haven't done this - its just too messy due to how Unity works. Things in a hierarchy but can be drawn in a completely different order, etc. There is no way to inherit anything from parents without having a script constantly looking it up which would be intrusive and slow.
-
I don't understand...
What I'm proposing is to have in the inspector the possibility to set the layer and layer order of ONE SINGLE the static sprite batcher (everything in it will have that layer and layer order). As you say it is one renderer when committed and the layer setting is done per renderer, can't this be done simple using something like the following?
myStaticBatcher.renderer.sortingLayerName = "Background";
When you are in edit you will simply assign the layer and layer order to all the children sprites. Is there no possibility of only changing the layer and layer order of the children when you change the one of the batcher? Having something constantly checking I agree is very bad. Maybe in that case something manual can be implemented (similar to the commit)? A manual button saying "assign layers"?
Just throwing some ideas for a possible implementation.
-
Yeah thats what I'm leaning towards. It would have to handle people setting the render layers on sprites internally while expanded, etc. Its just annoying that Unity doesn't let you inherit stuff like that. Eg. what happens when you create a new sprite internally? It will sort incorrectly until you assign the correct layer to it.
-
Yeah thats what I'm leaning towards. It would have to handle people setting the render layers on sprites internally while expanded, etc. Its just annoying that Unity doesn't let you inherit stuff like that. Eg. what happens when you create a new sprite internally? It will sort incorrectly until you assign the correct layer to it.
Totally true, but it is at least better than not even having the option of using layers with the batchers as it is now...
-
I will be adding the layer option probably in the next 2.4 beta. It really is quite simple to do that.
Having said that there isn't really a nice foolproof solution to this :( Maybe some obnoxious message boxes will do the job when someone tries to do something that isn't supported.