Procedurally Generated Scene Ysort Issues

Godot Version

Version 4.2

Question

I am procedurally generating a scene using noise and other factors. I am instantiating a tree scene like this:

@onready var Dtree = load(“res://World/DTree.tscn”)
for x in range(width)
for y in range(height)
if (code for if there is a tree in that spot)
get_parent().add_child.call_deferred(dtree)
dtree.position = (Vector2( x, y ))
dtree.y_sort_enabled = true

When I do this (for any object I add this way), it seems to just break the ysorting. My tree scene already has ysorting enabled, as does my procedurally generated scene node. The player too. This is only a problem when the object is instantiated, not when it is already a child of the scene. I’ve attached a picture of what it looks like when an object is instantiated (in this case it’s a bush), and when I just put the object in the scene.

If anyone has any ideas of what might be causing this issue, it would be greatly appreciated.

I can follow up with more information if necessary.

the parent of the nodes needs to activate y-sorting, not the children

I think I figured it out for anyone interested. All I had to do was instead of instantiating it with “get_parent().add_child.call_deferred(dtree)”, I just used “add_child(dtree)” no need to enable ysorting in code as the scene was already set to ysort. I’m still figuring out the problem with the tilemap, but I think I’m on the right track.