Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c# custom signal, After scene switching, you can still access the data of the previous scene. #83378

Closed
ice-ko opened this issue Oct 15, 2023 · 1 comment

Comments

@ice-ko
Copy link

ice-ko commented Oct 15, 2023

Godot version

Godot v4.2-beta1

System information

Win11

Issue description

Use the same script for multiple scenes, after switching scenes. Send a signal in a new scene, and the data returned after receiving the signal is the data in the previous scene.

202310151811.mp4

Steps to reproduce

  1. Start the game, click Next to switch scenes, click the mailbox to trigger the signal
  2. Receive the signal from the mailbox. The flag variable is the value in the previous scenario.

My English is not very good. There may be errors in the description. Please check the dmeo file, which contains a minimum test version.

Minimal reproduction project

TestDemo.zip

@raulsntos
Copy link
Member

Signals connected with += are not automatically disconnected when the node is freed. This is a bug and has already been reported in #70414. As a workaround you can use _ExitTree to disconnect the signal:

public override void _ExitTree()
{
    GameFlags.Instance.GameFlagsChanged -= UpdateNodes;
}

Alternatively, you can use the Connect method instead of += and that shouldn't need you to manually disconnect the signal:

public override void _Ready()
{
    defaultNode = GetNode<Node2D>("01");
    switchNode = GetNode<Node2D>("02");

    GameFlags.Instance.Connect(GameFlags.SignalName.GameFlagsChanged, Callable.From(UpdateNodes));
    UpdateNodes();
}

@raulsntos raulsntos closed this as not planned Won't fix, can't repro, duplicate, stale Oct 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants