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

When using a Node exported through a Resource, you can not listen to its signals. #82809

Closed
SwatDoge opened this issue Oct 4, 2023 · 2 comments · Fixed by #82843
Closed

When using a Node exported through a Resource, you can not listen to its signals. #82809

SwatDoge opened this issue Oct 4, 2023 · 2 comments · Fixed by #82843

Comments

@SwatDoge
Copy link

SwatDoge commented Oct 4, 2023

Godot version

4.1.1.stable

System information

Godot v4.1.1.stable - Windows 10.0.22621 - Vulkan (Compatibility) - NVIDIA GeForce RTX 3080 Ti (NVIDIA; 31.0.15.3168) - 12th Gen Intel(R) Core(TM) i9-12900K (24 Threads)

Issue description

With the code below, if you select a node and a signal name, it will await the execution of the signal correctly.

@export var signal_node: Node
@export var signal_name: String = ""

func _ready():
   await signal_node[signal_name]
   print("Signal happened!")

If I now move these exports to a Resource class, the code will no longer work:

class_name SignalInput
extends Resource

@export var node: Node
@export var name: String = ""
@export var signal_input: SignalInput

func _ready():
   await signal_input.node[signal_input.name]
   print("This will never show up")

Steps to reproduce

# SignalInput.gd
class_name SignalInput
extends Resource

@export var node: Node
@export var name: String = ""
# main.gd
extends Control

@export var signal_input: SignalInput ## (Node: Set to a timer node, Name: "timeout")

@onready var timer = $Timer

func _ready():
	await signal_input.node[signal_input.name] ## await timer.timeout
	print("[Method 1] Resource signal, will not appear") ## this should never run

Minimal reproduction project

source.zip

@SwatDoge SwatDoge changed the title When using a Node exported through a Resource, you can not listen for its signals. When using a Node exported through a Resource, you can not listen to its signals. Oct 4, 2023
@dalexeev
Copy link
Member

dalexeev commented Oct 5, 2023

I think this is not a bug, but rather an limitation. Exported nodes are serialized as NodePaths, not as objects. In the case of resources, you cannot access an outer node, this makes little sense since several nodes can use the same resource. So I think we should document the limitation, and also add an error/warning to GDScript if a non-Node derived class exports nodes.

@aXu-AP
Copy link
Contributor

aXu-AP commented Oct 5, 2023

I also encountered this limitation, ended up working around it by having the resource's owner pass a reference to the tree for resource to actually get the nodes. The exported values have to be NodePaths like in good old days.

I didn't get yet around to make an issue for it, but if you debug what's actually going on, it seems that your Resource creates just Node.new() instead of getting the actual node - that's why no errors are raised when trying to connect the signal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants