Godot Version
4.3
Question
Does anyone know what’s happening here?
Works in Editor
This code works when I used the editor (game starts fine, no errors reported)…
button.pressed.connect(EventManager.weapon_unlocked.emit.bind(unlocked_scene))
(“EventManager” is my Signal-Hub, “unlock_scene” is class PackedScene)
Breaks in Build
…BUT when I export a build, I get these errors (see below). The game runs (no crashes) but some scripts are broken:
An even simpler call where I bind a simple integer does not work neither:
# Does not matter if Signal is defined in EventManager or in the
# same script as the .connect happens. Always breaks in build.
signal test(hello : int)
# Works in Editor, breaks in Build
new_button.pressed.connect(EventManager.test.emit.bind(1))
Workaround #1 (works)
This is my current workaround. Instead if emitting the signal directly in .connect, I call a function which then calls the emit:
button.pressed.connect(weapon_unlocked.bind(unlock_scene))
...
func weapon_unlocked(unlocked_scene : PackedScene) -> void:
EventManager.weapon_unlocked.emit(unlocked_scene)
Workaround #2 (works)
Thanks @Locher ! This works as well:
new_button.pressed.connect(func() -> void: EventManager.weapon_unlocked.emit(unlock_scene))
Code
Here is the complete code (using workaround #2), if someone is curious. Maybe the problem is that I execute from CanvasLayer? Not sure…
extends CanvasLayer
class_name UnlockMenu
const UI_BUTTON = preload("res://ui/button/ui_button.tscn")
@onready var hbox_container: HBoxContainer = %hbox_container
func init(unlocks : Dictionary) -> void:
for i : int in unlocks.size():
# get unlock name
var unlock_scene : PackedScene = unlocks.values()[i]
var unlock_instance : Node = unlock_scene.instantiate()
var unlock_name : String = unlock_instance.get_stats().name
# add button
var new_button : Button = UI_BUTTON.instantiate()
hbox_container.add_child(new_button)
new_button.text = "Unlock " + unlock_name
new_button.custom_minimum_size.y = 50
if unlock_instance is Weapon:
new_button.pressed.connect(func() -> void: EventManager.weapon_unlocked.emit(unlock_scene))
elif unlock_instance is EnemySpawner:
new_button.pressed.connect(func() -> void: EventManager.enemy_unlocked.emit(unlock_scene))
new_button.pressed.connect(func() -> void: EventManager.unlock_chosen.emit())
new_button.pressed.connect(queue_free) # close unlock menu
unlock_instance.queue_free()