add_child instance seems to do not respect the ysort property of a a Tilemap node

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Antilo

Hello!
i have the following structure of nodes

  • navigation2d
    ->TileMap (floor)
    ->TileMap (walls) (y-sort property on)
    → ->Animation Character Scene1 (Player)
    → ->Animation Character Scene2 (Enemy)

when i do it this way it works at it should… and the ysort property hierarchy works
but i need to create instances of enemy for it respawn so in the navigation2D node i have the following script:


var Enemy = preload("res://Enemy.tscn")
func _ready():
     var new_enemy = Enemy.instance()
     get_node("wall").add_child(new_enemy)

if i create the enemy this way… the y sort is not respected, and the enemy is draw over everything, including walls…

Any ideas how to go on?

:bust_in_silhouette: Reply From: Antilo

Ok never mind… i answer myself… during process it seems that i change manually the Z-index and as it seems it has priotity over Ysort if it is intanced through code … but not if it is added manually…