0 votes

hi guys,

i have 3 scenes
main.tscn player.tscn enemy.tscn(this have areadbody)

in enemy.gd script

signal exited
func _on_enemy_body_exited(body):

in player.gd script

func test():

but the connect function is not written in player script because both the enemy and player are dynamically instanced in the main node

in main.gd script

onready var player_scene = preload("res://player.tscn")
onready var enemy_scene = preload("res://enemy.tscn")

enemy_scene.connect("exited", player_scene, "test")

but its not working, how to connect the signal of enemy to player

in Engine by (14 points)

1 Answer

0 votes

I imagine you're getting an error message. You should really include that in your post.

preload() loads a scene file from disk and returns a PackedScene object, which can be used to make instances.

connect() needs to use paths to the nodes that exist in the tree. Where is your code that's instancing the player and enemy? That is where you need to call connect.

by (20,921 points)
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.