0 votes

Hello,

I am trying to use a singlton to manage signals emitted by enemy bullets in my game when they collide with a TileMap. However, I am getting the error

W 0:00:00.857 The signal 'highlighted' is declared but never emitted.
<C++ Error> UNUSEDSIGNAL
Event
Bus.gd:8

The code for the singleton is

extends Node

func _ready():
    pass

# BATTLE SCENE SIGNALS

signal highlighted(ebpos)

With the signals being emitted in the EnemyBullet scene as such

func _on_EnemyBullet_body_entered(body):
if body.is_in_group('Player'):
    body.take_damage(1)
    queue_free()
if body.is_in_group('Cell'):
    EventBus.emit_signal("highlighted",self.position)
    print("collision test")

Here the the collision test is printing so the signal should be emitted, yet I continuously get the error.

For reference the signal should be then connected in the BattleStage scene with the following code

func check_for_highlight():
if self.has_node("res://Battlescreen/Scenes/EnemyBullet.tscn"):
    EventBus.connect("highlighted", self, "highlight_cell")


func highlight_cell(ebpos):
    var tile_pos = ebpos.snapped(Vector2(116,76))
    var tilemap_pos = $Game_grid.world_to_map(tile_pos)
    var tx = tilemap_pos.x
    var ty = tilemap_pos.y
    $Game_grid.set_cell(tx,ty+5, 1)
    print("test")

I tried this before without the singleton and it worked except I was experiencing problems which I couldn't solve and assumed maybe using a singleton to manage the signals of nonpermanent scenes/nodes could solve my problems, but I am not sure why the signal is not being emitted.

If you could help me I would appreciate it!

Thanks!

in Engine by (15 points)

How do you access the EventBus singleton? I assume your scripts do this:
var EventBus = $"/root/EventBus"

I'm not seeing any problem with the code you've shared. Mind sharing the complete scripts?

Hi, thanks for your comment. I am still getting the error that the signal is never emitted, but I am getting the highlight I was looking for, so I guess it is. The only problem is now the tilemap itself isn't really working properly so I have to investigate that a bit.

Thanks!

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.