I'm sorry if this is a stupid question but I am new to Godot. I've fooled around a bit in other engines before and so far I've been able to get things working and/or find answers when something wasn't working in Godot but I don't have a clue what's going on here. I have a script called Player, which extends a script called Character, which extends CharacterBody2D. I also have a script called SceneManager. The SceneManager needs to be able to call functions on the Player so I had the Player, as part of the _ready function, send out a signal, sending "self" to the SceneManager. The signal's being sent out and is arriving but "self" is a CharacterBody2D with the name of the Player's object, not a Player, and the SceneManager can't find the function from the Player script on this CharacterBody2D.
Can anybody please explain why "self" is and isn't the thing itself? And what can I do to let the SceneManager call functions on the Player? Thanks!
I can post the code if it'll help.
Script Sending "Self" that Is and Isn't Self
Narnialover Make a custom signal with an argument of the exact type or cast a received argument to the exact type.
Narnialover In your signal handler function in SceneManager try something like this:
func _on_signal_from_player(player: Player):
player.call_player_function()
Or cast the CharacterBody2D object to an object of class Player:
func _on_signal_from_player(character: CharacterBody2D):
var player = character as Player
if player:
player.call_player_function()
Ok, now I feel like an idiot. Going through, collecting code to post and writing an explanation of it... I found a missing underscore in the function call and now it works. I'm just going to crawl away now.