Spawner works on the editor preview, but not in the exported project. What's wrong?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By vandalk
:warning: Old Version Published before Godot 3 was released.

Hello Everyone!

I’m creating a beat’em up game in Godot! I’m trying to test player controls and to do that I start the scene with 3 enemies, and spawn 3 more whenever all enemies are killed.

This is the code for my spawner:

extends Node2D

##########################
# Class Member Variables #
##########################
const ENEMY = preload("res://Enemies/Enemy01/Enemy01.tscn")
const MAX_ONSCREEN_ENEMIES = 4

onready var entities_layer = self.get_node("../EntitiesLayer")
onready var player = entities_layer.get_node("Player")


#############################
# Custom Method Definitions #
#############################
func spawn_enemies():
	var children = entities_layer.get_child_count()
	if children < 2:
		var to_spawn = MAX_ONSCREEN_ENEMIES-children
		for n in range(to_spawn):
			var enemy = ENEMY.instance(true)
			var posx = player.get_pos().x + floor(rand_range(-45,46))
			var posy = player.get_pos().y + floor(rand_range(-11,12))
			enemy.set_pos(Vector2(posx,posy))
			
			entities_layer.add_child(enemy)
			pass
	pass

###########################
# Engine Standard Methods #
###########################

func _ready():
	randomize(true)
	
	set_process(true)
	pass

func _process(delta):
	spawn_enemies()
	pass

It works fine when I’m testing the game in the editor, but once I export it, the resulting executable doesn’t spawn anything, after I kill the first 3 enemies.

Is there something wrong on the code above? Is it some project settings? How can I try to debug the exported executable to try and find out what’s happening?

If you need more information about the project, or want to test it out in the editor yourself, you can find it here on github - GitHub - eh-jogos/Beatwo: A King Of The Hill beat'em up that uses only two buttons. Done with Godot.

:bust_in_silhouette: Reply From: vandalk

Alright! Found out how to debug an exported project from an answer for another question at the forum! You only need to execute your game from the command line to see the debugging happening there!

From there I found out my problem was on the instance() call:

var enemy = ENEMY.instance(true)

That true didn’t need to be there and only work on the editor apparently. I don’t know why I though I needed that true to be honest. Just erasing it and leaving:

var enemy = ENEMY.instance()

made everything work!

I completely skipped that “true” there, tbh. I didn’t even know you could do that, all code I’ve seen so far use just .instance().

Glad you found it, good catch. :slight_smile:

rredesigns | 2017-06-08 04:21