Enemies generating before starting the game, game freezes when timers start

Godot Version

Latest

Question

Hi there guys, i’m following the tutorial, and for some reason i don’t know, all the enemies of dodge the creeps are generating before starting the game (pressing the start button), if i set the timers to auto start, the game freezes, and also the character is able to move before the game starts.

I correctly connected the signals required on the tutorial, here are my scripts:

main.gd

extends Node
@export var mob_scene: PackedScene
var score
func _ready():
	get_tree().call_group("mobs", "queue_free")

func game_over():
	$ScoreTimer.stop()
	$MobTimer.stop()
	$HUD.show_game_over()

func new_game():
	$HUD.update_score(score)
	$HUD.show_message("Get READY!!")
	score = 0
	$Player.start($StartPosition.position)
	$StartTimer.start()
func _on_score_timer_timeout():
		score +=1 
		$HUD.update_score(score)

func _on_start_timer_timeout():
	$MobTimer.start()
	$ScoreTimer.start()
func _on_mob_timer_timeout():
	# Create a new instance of the Mob scene.
	var mob = mob_scene.instantiate()

	# Choose a random location on Path2D.
	var mob_spawn_location = $MobPath/MobSpawnLocation
	mob_spawn_location.progress_ratio = randf()

	# Set the mob's position to the random location.
	mob.position = mob_spawn_location.position

	# Set the mob's direction perpendicular to the path direction.
	var direction = mob_spawn_location.rotation + PI / 2

	# Add some randomness to the direction.
	direction += randf_range(-PI / 4, PI / 4)
	mob.rotation = direction

	# Choose the velocity for the mob.
	var velocity = Vector2(randf_range(150.0, 250.0), 0.0)
	mob.linear_velocity = velocity.rotated(direction)

	# Spawn the mob by adding it to the Main scene.
	add_child(mob)

mog.gd

extends RigidBody2D
func _ready():
	var mob_types = Array($AnimatedSprite2D.sprite_frames.get_animation_names())
	$AnimatedSprite2D.animation = mob_types.pick_random()


func _on_visible_on_screen_notifier_2d_screen_exited() -> void:
	queue_free()
`
player.gd `extends Area2D
@export var player_speed = 400;
signal hit
var size; 
func _ready():
	size = get_viewport_rect().size
	
func _process(delta):
	var velocity = Vector2.ZERO
	if Input.is_action_pressed("move_right"):
		velocity.x +=1
	if Input.is_action_pressed("move_left"):
		velocity.x -=1
	if Input.is_action_pressed("up"):
		velocity.y -=1
	if Input.is_action_pressed("down"):
		velocity.y +=1
	if velocity.length() > 0:
		velocity = velocity.normalized() *player_speed
		$AnimatedSprite2D.play()
	else:
		$AnimatedSprite2D.stop()
	position += velocity * delta
	position = position.clamp(Vector2.ZERO, size)
	if velocity.x != 0:
		$AnimatedSprite2D.animation = "walk"
		$AnimatedSprite2D.flip_v = false
		$AnimatedSprite2D.flip_h = velocity.x <0
	elif velocity.y !=0:
		$AnimatedSprite2D.animation = "up"
		$AnimatedSprite2D.flip_v = velocity.y > 0
	


func _on_body_entered(body: Node2D) -> void:
	hide()
	hit.emit()
	$CollisionShape2D.set_deferred("disabled",true)
func start(pos):
	position = pos
	show()
	$CollisionShape2D.disabled = false
`
hud.gd `extends CanvasLayer
signal start_game

func show_message(text):
	$Message.text = text
	$Message.show()
	$MessageTimer.start()
func show_game_over():
	show_message("Game Over")
	# Wait until the MessageTimer has counted down.
	await $MessageTimer.timeout

	$Message.text = "Dodge the Creeps!"
	$Message.show()
	# Make a one-shot timer and wait for it to finish.
	await get_tree().create_timer(1.0).timeout
	$StartButton.show()
func update_score(score):
	$ScoreLabel.text = str(score)

func _on_start_button_pressed() -> void:
	$StartButton.hide()
	start_game.emit


func _on_message_timer_timeout():
	$Message.hide()

Any idea? i checked the signal connections and they seems good.

Regards and thank you.

By “freezes” do you mean a stack trace is presented? If so can you post what it says and what line of code it points at?

If I understand the code, your player looks to be instantiated already before the start of the game, so unless you disable their process function yes they are going to be able to move soon as you start game from editor and all the nodes ready up.

Second, have you placed a print() in mob ready func and in the mob_timeout func?

I am not sure what tutorial this is from, but I don’t know if I’d do it like this.

I’d probably instantiate the ‘world’ when you press the start button, the world would either have the player there in it, or would instantiate player, setting their position, and then it’d also then start spawning monsters.