I have a simple trail effect. I have a script attached to Line2D as follows:
extends Line2D
export (int) var max_length = 20
func _ready():
set_as_toplevel(true)
func _physics_process(delta):
var p = get_parent().global_position
add_point(p)
if len(points) > max_length:
remove_point(0)
Scene tree is as follows:
KinematicBody2D
Or I can create the scene tree this way:
KinematicBody2D
It makes no difference which way I construct the scene tree. Line2D always renders on top of the Polygon2D.
When I comment out the line with set_as_toplevel(true)
, the problem is fixed (i.e., the draw order is respected - the Line2D is drawn either in front of or behind Polygon2D). But I need set_as_toplevel(true)
to make the transformations work.
Why does this happen? How do I fix this?
Edits: Clarity.