0 votes

I am programmatically instantiating a scene with the player character. When this scene is instantiated I want to send a signal to the camera. The signal should set the player character to be the target of the camera.

This is the main scene structure

GameManager
    Camera
    SceneSwitcher
        (instantiated scene will be here)

The new scene is instantiated as a child of the SceneSwitcher. This is SceneSwitcher script where I am trying to connect the signal from the instantiated scene.

func loadScene(scene):
    var newScene = load(scene).instance()
    add_child(newScene)
    newScene.connect("focus", camera, "setCameraTarget")

The instantiated scene is emitting this signal:

signal focus(target)

func _on_Player_tree_entered():
    emit_signal("focus", player)

This is the function in the camera that I want to run when the signal connects:

func setCameraTarget(object):
    print("camera set on: ", object.name)
    target = object

Seems like the signal never connects because I never see the print message "camera set on: player".

Godot version v3.4.2.stable.official [45eaa2daf]
in Engine by (12 points)

1 Answer

0 votes

is _enter_tree() signal connected to the _on_Player_tree_entered?

did you try adding a print("tree entered") into the _on_Player_tree_entered() function to make sure it's actually getting called?

by (1,346 points)

It is, I did exactly that and the onPlayertreeentered() is getting called.

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 Frequently asked questions and 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 [email protected] with your username.