0 votes

Hi, i want to run a specific line of code after the scene was changed.
I changed the scene with (get_tree.change_scene()).
Is there a specific signal for this or something else?
Thanks in advice.

Godot version 3.2.3
in Projects by (53 points)

Why don't you add the code you want to run in the main script of the scene that you are switching to.

Ok that's it.
After the scene was changed:

position = Vector2(0,100)

In to the player script.

See if it works for you. The script where you are using get_tree.change_scene(), try adding onready var playerReference = get_parent().get_node("Player") and then use playerReference.position = Vector2(0,100)
I am assuming you have named your player Node as Player and it is part of the main Scene.

Thanks i'll try it. But my problem is that this line of code must run after the change scene into the new scene . I used a node 2d with a script to interconnect this two scenes. My real problem is how can i emit a signal after a scene was changed.

Have you tried using Signals? Can you share your project ? Maybe we can find a solution.

Yes i use signals but my problem is this:
"How can i emit a signal AFTER the scene was changed?"

I guess by using a custom signal in the _ready() function. You first declare a signal as

signal example

then you use emit_signal("example") in _ready() function. Then you select the node with which the script containing example signal is attached and go to the Inspector tab where you will see a example signal under Signals that you created. Connect that and you're good to go. However you must have a script in the scene that you are switching to. There are definitely people here in the community with amazing knowledge but I don't know why they haven't answered your question yet. Let's hope they'll resolve your query but make sure you try my fix too.

I do exactly like that but it doesn't work. I connect the signal to the main script but it doesn't work.

1 Answer

0 votes

do you haveposition = Vector2(0,100) inside a player's response to signal function?

by (104 points)
