Enemies spawning on scene there not being instantiated on

Godot 4

please help I’ve posted before on this but no ones helping, it was fine until I made a tile map then deleted it because it was showing on a separate scene for some reason and now I can’t stop the enemy from spawning on the wrong scene. Enemy 2 is spawning on Enemy 1’s scene.

scene 1 code:
extends Node
@export var mob_scene: PackedScene
func _ready():

func _process(delta):

func _on_timer_2_timeout():

func _on_timer_4_timeout():
var mob = mob_scene.instantiate()
var mob_spawn_location = $Path2D/PathFollow2D
var direction = mob_spawn_location.rotation + PI /2
mob.position = mob_spawn_location.position
direction += randf_range(-PI / 4, PI / 4)
mob.rotation = direction
var velocity = Vector2(randf_range(150.0, 250.0), 0.0)
mob.linear_velocity = velocity.rotated(direction)

func _on_timer_3_timeout():

enemy 1 code:
extends RigidBody2D

func _on_visible_on_screen_notifier_2d_screen_exited():

scene 2 code:

extends Node
@export var mob_scene2: PackedScene
func _ready():

func _on_timer_5_timeout():

func _on_timer_6_timeout():
var mob_spawn_location2 = Vector2(600, randf_range(-450 , 450))
var mob2 = mob_scene2.instantiate()
var direction = 0
mob2.rotation = direction
mob2.position = Vector2(600, randf_range(-450 , 450))
var velocity2 = Vector2(randf_range(-150.0, -250.0), 0.0)
mob2.linear_velocity = velocity2.rotated(0)

enemy 2 code:

extends RigidBody2D
func _enter_tree():

func _on_visible_on_screen_notifier_2d_screen_exited():

You may have already tried some of these, but this is what I can see based on the code:

  • In the _on_timer_4_timeout() function in Scene 1, you’re instantiating mob_scene but not checking if it’s valid. Make sure mob_scene is set to the correct scene.
  • In Scene 2, in the _on_timer_6_timeout() function, you’re setting the position of mob2 to (600, randf_range(-450 , 450)) but also setting mob_spawn_location2 to (600, randf_range(-450 , 450)). You should use only one of these for setting the position.
  • Ensure that the scenes referenced by mob_scene and mob_scene2 are indeed the correct enemy scenes.
  • Check if there are any leftover references to the deleted tile map that might be affecting the spawning of enemies.

I can’t read unformatted code. Please put it in in a code block.



1 Like

How can I check for the references to the deleted tile map?

I fixed it, all I did was delete the scene then rebuild it. I still don’t really know what the issue was but it’s fixed none the less.

Nvm, apparently at some point (not sure when) I had attached a node2D underneath the player scene