This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

I'm having a bit of trouble with getting a sprite to follow (or appear on) a PathFollow2D when I create the PathFollow2D via script.

func _ready():
path2d =
curve = path2d.curve

#Add curve points to create a planetary orbit
curve.add_point ( Vector2 (0, yrad), Vector2( 0, 0 ), Vector2( xrad, 0 ), -1 )
curve.add_point ( Vector2 (xrad, 0), Vector2( 0, 0 ), Vector2( 0, -yrad ), -1 )
curve.add_point ( Vector2 (0, -yrad), Vector2( 0, 0 ), Vector2( -xrad, -0 ), -1 )
curve.add_point ( Vector2 (-xrad, 0), Vector2( 0, 0 ), Vector2( 0, yrad ), -1 )
curve.add_point ( Vector2 (0, yrad), Vector2( 0, 0 ), Vector2( 0, 0 ), -1 )

#Add a new PathFollow2D as a child of the Path2D
var followpath = path2d.get_child(0)

#Create a test sprite and set its texture
var testsprite =

#Add testsprite to the FollowPath2D

#Draw orbit of planet
func _draw():
draw_polyline(curve.get_baked_points(), Color(1,1,1,.1), 2.0)

func _process(delta):
followpath.set_offset(followpath.get_offset() + 50 * delta)

The above is a simplified version of what I'm trying to do (my actual script generates multiple orbits, then pulls from sprite factories etc) but even the above isn't working for me.

If I print the name of "testsprite" it gives me Sprite 12312 or whatever random number it generated, as opposed to "Null," but there is no sprite visible in-game (as far as I can see). I see the drawn Path2D, but not the child "testsprite."

I also deleted the background in the scene to ensure the sprite isn't simply appearing beneath the background.

If I haven't given enough info, let me know and I can add more. Thank you in advance!

in Engine by (48 points)
edited by

1 Answer

+1 vote
Best answer

Well, I feel dumb. Apparently I forgot to parent my Path2D into the scene. Made Path2D a child of my root node and now everything's working fine.

by (48 points)
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.