Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to YSort sprites underneath the smoothing node on a Player with tilemap. #31

Closed
NikkuNakku opened this issue Mar 15, 2023 · 11 comments
Labels
documentation Improvements or additions to documentation

Comments

@NikkuNakku
Copy link

YSort is enabled properly on 'TileMap' node and 'Level' node. When dragging 'Player' node in the editor, the YSort seems to work. So it's only broken when running the game.

Minimum reproduction project: smoothingysortsetup.zip

(At least I believe that's how a minimum reproduction project works. First time doing this haha. Just everything stripped down to the bare minimum needed to showcase the issue I'm assuming.)

@lawnjelly
Copy link
Owner

Thanks, will check it as soon as I can! 👍

@NikkuNakku
Copy link
Author

I came back to experiment a little with it. Turns out it was as simple as disabling 'global out' on the smoothing node. 😝 I had tried it before but I guess I had something set up wrong.

@lawnjelly
Copy link
Owner

lawnjelly commented Mar 16, 2023

Having a little look. I'm not an expert at y-sorting, but I think the problem is that the Level y-sort sorts the immediate children, i.e. Player and TileMap, and the tilemap position is 0,0.

I'm not 100% sure this is to do with smoothing actually, because the same occurs if I move the Sprite to be a child of CharacterBody2D.

Related to https://godotengine.org/qa/65742/how-to-ysort-kinematic-body-and-tilemap ?

@lawnjelly
Copy link
Owner

I can't actually get this to work with Godot 4.0 stable even without smoothing addon. 😆

I did get it to work at one point fiddling with the project, but I have no idea why. Given that there may be some bugs in y sorting in Godot 4 I would recommend starting with a project that works without smoothing, then we can work from there.

I very rarely work on Godot 4 hence I'm not super familiar with it, what are bugs etc.

@NikkuNakku
Copy link
Author

That's actually really odd. I did get it to work with the player smoothing node setup, have to turn on YSort on the Player node and disable "global out" on the smoothing node, which did it. I don't know why you're unable to get it to work with normal nodes.

So I definitely know the tilemap position being 0,0 isn't it, but as you said 4.0 can be pretty buggy still, so it just seems like a bunch of janky-ness from it. Thanks for taking the time to look into it!

@chaysest
Copy link

Just adding a +1 to @NikkuNakku, I have Y sorting working in 4.0.1 but if I use a smoothing node all Y sorting with that CharacterBody2D (and associated sprite) breaks for me, not just tilemaps.

@lawnjelly
Copy link
Owner

Just adding a +1 to @NikkuNakku, I have Y sorting working in 4.0.1 but if I use a smoothing node all Y sorting with that CharacterBody2D (and associated sprite) breaks for me, not just tilemaps.

I'll try and have another look, but any more minimum reproduction projects for this would be really useful. 👍

@lawnjelly
Copy link
Owner

lawnjelly commented Apr 23, 2023

I've managed to reproduce it with a simpler project:
smoothingysortsetup.zip

When set to global in / out, it seems to break the y sorting. I'll have a look further but this could be a bug in core, possibly to do with y sort not working when set_as_toplevel() is set.

Good news is it does seem to work in local mode. If you make sure the smoothing node has no transform applied (from a parent) turn off the global in / out, set the target, and it seems to work ok.

EDIT:
Yes this seems to confirm there is a bug in Godot 4 when using y sort with toplevel:
https://www.reddit.com/r/godot/comments/xfg1u1/godot_4_any_way_to_simulate_top_level_behavior/

Also seems to happen in Godot 3.x. No idea why yet, will have a look at the core source code.

UPDATE:
It looks like when toplevel is set, it adds the canvas item as a child of the canvas_layer or viewport, rather than the direct parent. Hence y sorting is all broken. So it looks like for 2D with y sort, the only way around this is to manually ensure that there is no transform applied to the smoothing node (i.e. don't hang it off the player as suggested in the docs) and turn off global out. It may still be fine with global in, I'll test this. Yes, global in is fine, global out breaks y sort.

I'll add this to the docs. 👍

I don't think this should affect core 2D interpolation ( godotengine/godot#76252 ) as that works internally in VisualServer, but I'll double check.

@lawnjelly lawnjelly added the documentation Improvements or additions to documentation label Apr 23, 2023
hsandt added a commit to hsandt/ld53 that referenced this issue May 5, 2023
- set Y Sort Enabled on all recursive parents of all gameplay sprites (PC and obstacles)
- set Z index to 5 on PC and obstacles root
- clear PC Z index override in scenes

This still doesn't work because of the Smoothing2D node on PC which messes up rendering due to set_as_toplevel lawnjelly/smoothing-addon#31

I couldn't fix it just by unchecking global in/out because it caused the PC to be super fast.

In addition, for some reason, now even simple sprites without instantiated scenes fail to follow Y Sort Enabled.
@hsandt
Copy link

hsandt commented May 11, 2023

Sorry, but unchecking global out will make my sprite go away super fast, like at 2x speed, compared to the collider. So I cannot use this trick.
Are they conditions in which unchecking some flags is not safe? It should always recalculate transform so the final position is correct, right?

I'll try to open an issue but I need to make a MWE.

EDIT: I started making a MWE and realized the offset was exactly the initial character position that itself offset the Smoothing node I set as child. I read the paragraph you added to the README (https://github.com/lawnjelly/smoothing-addon#y-sort-in-2d) and see that I should not parent the Smoothing node. So I'll just follow the instructions closely.

EDIT 2: I confirm it works, even if you dynamically reparent Smoothing2D to an outer node at runtime. But if you do so, remember to readjust the global Z index! (or work with global Z index to start with)

@lawnjelly
Copy link
Owner

I'll leave this issue open in case others have the same problem.

@lawnjelly
Copy link
Owner

Should be fixed by #39, #40 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants