0 votes

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():

func _physics_process(delta):
    var p = get_parent().global_position
    if len(points) > max_length:

Scene tree is as follows:


  • Line2D
  • Polygon2D

Or I can create the scene tree this way:


  • Polygon2D
  • Line2D

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.

Godot version v3.4.2.stable.official [45eaa2daf]
in Engine by (18 points)
edited by

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.