System for changing z-index on the fly?

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

I am wondering how can I make it so all units that are position.y above building they are rendered behind it, and if their position is below the building then they rendered above it…

Let me know if you can’t understand the question and need images…

Currently I try following, but it does not do anything and even if it did I imagine it would be quite taxing ?

func _process(_delta):
for i in get_children():
	if i.has_method("look_at"):
		if i.global_position.y < $Building.global_position.y:
			i.z_index = -1
			i.z_index = 3
:bust_in_silhouette: Reply From: exuin

You’re looking for a YSort node.

Thanks, I look into it!

wildboar | 2021-02-19 03:47