cannot instantiate a packedscene, what to do instead

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Daesina

in documentation your first 2d game,the main game scene,there is this thing:
func _on_mob_timer_timeout():
# Create a new instance of the Mob scene.
var mob = mob_scene.instantiate()
which does not work on4.0.3 and reports an error.
what to do instead to create a new instance of the mob scene?
and please update your documentations

maybe link the tutorial you’re following and which step you are on?

putper | 2023-06-02 08:23

The main game scene — Godot Engine (stable) documentation in English
the step is on the top of the longest script in the link

Daesina | 2023-06-02 09:36

And what is the error you are getting?

putper | 2023-06-02 09:38

Worth verifying that you’ve assigned the scene in the editor:

You can assign this property’s value in two ways:

  • Drag mob.tscn from the “FileSystem” dock and drop it in the Mob Scene property.
  • Click the down arrow next to “[empty]” and choose “Load”. Select mob.tscn.

The documentation is correct.

spaceyjase | 2023-06-02 09:41

:bust_in_silhouette: Reply From: putper

so I assume in the script you define the method:

func _on_mob_timer_timeout():
    print("mob timed out!")
    # rest of code from tutorial

But I think you might’ve missed this step:

Now connect the timeout() signal of each of the Timer nodes
(StartTimer, ScoreTimer, and MobTimer) to the main script.

To explain, for each timer you must:

  1. Select the timer in the SceneTree (top-left).
    select a timer

  2. Go to the Node tab (top-right), and under Signals right click the timeout() method and click connect.
    node -> signals -> timeout() -> connect

  3. Select the matching method. For example, for MobTimer you select _on_mob_timer_timeout().