Packed Scene and Spawning?

Godot Version

4.2.2

Question

Hello all,

I have a question regarding a packed scene and how to spawn the item that came from a Udemy series on making a proper platformer. The idea is a simple one but complex for me, it makes a dust particle type effect when the player jumps in the air.

However, nothing is appearing when jump is pressed. And I need to need to track down the culprit. I have a scene that has the particle effect as an animated sprite, so, and this is the code in I have in the character scene does the following look right:

@export var jumpDust : PackedScene; #drag and drop`

in the jump function

func jump():
	if is_on_floor():
		velocity.y = jump_velocity;
		spawn_dust(jumpDust)
		print("dusty roads");

Then in the spawn function:

#new Function that will make the correct dust appear when jumping
func spawn_dust(dust_jump: PackedScene): 	#packed scene to drag and drop
	var jump_dust = dust_jump.instantiate();	#instantiate
	jump_dust.position = position;				#set position to the sprite
	print("hello sweetie")
	#pass

Does this code look right? The prints are working

In the packed scene I have this code:

extends AnimatedSprite2D

# Called when the node enters the scene tree for the first time.
func _ready():
	play();
    print("ready to play");
	#pass # Replace with function body.

func _on_animation_finished():
    print("finished")
	queue_free();
	#pass # Replace with function body.

Does this also look right? “Ready to Play” and “finished” are NOT showing.

As always here is a thankyou in advance.

Looks like jump dust needs to be added to the scene tree:

add_child(jump_dust)
4 Likes

Well, I definitely missed that line in the lesson, I know why because the video player had a great big purple playback line running through it.

Still, after putting that line with just the add_child(whatever), which I used in the recent past with an actual CPUParticle2D effect which worked fine, it still didn’t work. I had had to go and put:

  • get_parent().add_child(whatevs)

Goodness knows why. Anyway, thankyou for finding the error though, I just couldn’t see what the problem was - literally :grinning:.

Quick tip, get_parent().add_child() is the same as add_sibling() :slight_smile:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.