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 Engine by (55 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 (106 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.