Hi, I am following this tutorial "Your first 2D Game" here: https://docs.godotengine.org/en/stable/getting_started/first_2d_game/05.the_main_game_scene.html

When I run the main scene, only the player character shows up. No enemies spawn
Am I doing something wrong?
Here is my code

extends Node

@export var mob_scene: PackedScene
var score

func _ready():
	new_game()

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

func new_game():
	score = 0
	$Player.start($StartPosition.position)
	$StartTimer.start()
	
func _on_MobTimer_timeout():
	# Create a new instance of the Mob scene.
	var mob = mob_scene.instantiate()

	# Choose a random location on Path2D.
	var mob_spawn_location = get_node(^"MobPath/MobSpawnLocation")
	mob_spawn_location.progress = randi()

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

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

	# 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)

func _on_ScoreTimer_timeout():
	score += 1
	


func _on_StartTimer_timeout():
	$MobTimer.start()
	$ScoreTimer.start()
  1. Place ~~~ before and after the code you posted so that it can be read.
  2. Post the link to the tutorial. There are many versions.
  3. Post the exact Godot version that you're using.

    Hi, I managed to find the issue by downloading the completed project of this tutorial

    The issue lies in func _on_mob_timer_timeout():
    there is no mob_timer node in my project, i have to follow the name.
    it looks like the tutorial did not mention this

    Edit: I recreated the project again and mobs did not appear

      DaveTheCoder
      thanks for the advice and replying, I did not see your message when I found the solution

      it turns out I forgot to link the tutorial in OP
      I am using godot 4.2

      Thanks for fixing the code display.

      For reference, here's the tutorial link with the Godot version specified:
      https://docs.godotengine.org/en/4.2/getting_started/first_2d_game/05.the_main_game_scene.html
      Using the "stable" link has the problem that it changes when a new stable version of Godot is released.

      By exact Godot version I meant this: v4.2.1.stable. You can copy that to the clipboard by clicking on the version at the bottom right of the editor window, or in the Help / About Godot dialog. But that detail probably isn't relevant in this case.

      game_enjoyer there is no mob_timer node in my project,

      The tutorial includes this:

      Now, add the following nodes as children of Main, and name them as shown (values are in seconds):
      Timer (named MobTimer) - to control how often mobs spawn

      Is that what you meant?

        DaveTheCoder
        hi, sorry to bother you but I am experiencing the same error again.

        I edited the OP script, and ran the scene but enemies mobs do not appear

        Edit: Here is my exported project, if anyone can please help me on this issue, I am truly grateful.
        Once again, the issue is no enemies spawn when I start the game

        [https://github.com/claritybear/TUTORIAL-PROJECT](https://)

        There is a ^ in var mob_spawn_location = get_node(^"MobPath/MobSpawnLocation")
        The project would be helpful, if the above wasn't the issue.

          game_enjoyer Is the github link enough?

          Yes.

          You didn't connect the timeout signals for the three Timers. They need to be connected to the corresponding functions in the main.gd script.
          As the tutorial says:

          Now connect the timeout() signal of each of the Timer nodes (StartTimer, ScoreTimer, and MobTimer) to the main script. StartTimer will start the other two timers. ScoreTimer will increment the score by 1.

          https://docs.godotengine.org/en/4.2/getting_started/step_by_step/signals.html#connecting-a-signal-in-the-editor

          After I connected the signals, the enemies appear.

          trizZzle There is a ^ in var mob_spawn_location = get_node(^"MobPath/MobSpawnLocation")

          Actually, that's valid. I had to look it up in the documentation. The ^ makes the string a NodePath, which is the correct type of the argument of get_node(). It's not required, since NodePath has a constructor that converts a String to a NodePath.

            DaveTheCoder

            Thanks so much, I was on the fence for switching to Unity.
            Some of my favorite games are created in Unity.

            I'll continue godot for now and see how it goes

            DaveTheCoder

            DaveTheCoder trizZzle There is a ^ in var mob_spawn_location = get_node(^"MobPath/MobSpawnLocation")

            Actually, that's valid. I had to look it up in the documentation. The ^ makes the string a NodePath, which is the correct type of the argument of get_node(). It's not required, since NodePath has a constructor that converts a String to a NodePath.

            Looked like a typo to me as it wasn't in the linked tutorial. 😃

            @MikeCL Perhaps it would make sense to rename this thread so that the title is not misleading? Since there is no error in the tutorial.

            DaveTheCoder

            my god, another issue I have is now when character dies, MobTimer does not stop and keep spawning mobs?

            Edit: Nevermind, it seems my StartTimer has the autostart property on, after turning it off mobs stop spawning after character dies

            DaveTheCoder

            I ran into another issue..., I am really so frustrated

            On this site: https://docs.godotengine.org/en/stable/getting_started/first_2d_game/06.heads_up_display.html
            "In the Node tab, connect the HUD's start_game signal to the new_game() function of the Main node by clicking the "Pick" button in the "Connect a Signal" window and selecting the new_game()"

            I am unable to connect to new_game, there is no option

            I updated my github as well

            EDIT: I NOTICED another solution which is to type new_game in the Filter Methods box, this will create a new_game function
            Does this work as well?

            The problem is that the script HUD.gd is attached to both the Main node and the HUD node. That's why the functions in main.gd are not showing up in the connect dialog.

            Right-click on the Main node, and attach the script main.gd.

              DaveTheCoder

              I am finally done with this tutorial, I plan on testing myself and adding additional features to this game, but it won't be on this thread.

              Thank you very much and everyone else who helped on this thread.
              I just have 1 issue, I was tinkering with the source code for this game on github and ran into an error, its up to you if you want to help with this, i did not touch the mob script or tscn at all

              The error is "Script inherits from native type Rigidbody2d so it cant be assigned to an object of type pathfollow2d

              here is the folder for the project: https://github.com/claritybear/Original-dodge-the-creps

              Script inherits from native type Rigidbody2d so it cant be assigned to an object of type pathfollow2d

              This is literally the error. The script is attached to the wrong node type; i.e. the extends part of the script needs to match the node type.

              Script inherits from native type 'RigidBody2D', so it can't be assigned to an object of type: 'PathFollow2D'

              The script mob.gd is attached to the node Main/MobPath/MobSpawnLocation in the scene main.tscn. Detach it.