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

Signal.is_null() method isn't describing what the function is actually doing #9831

Closed
trFate opened this issue Aug 25, 2024 · 2 comments · Fixed by godotengine/godot#96066
Closed
Labels
area:class reference Issues and PRs about the class reference, which should be addressed on the Godot engine repository enhancement

Comments

@trFate
Copy link

trFate commented Aug 25, 2024

Godot version is 4.3

I was trying to detect if a signal has a valid object linked to it, reading the doc I ended up on the Signal.is_null() method which states "Returns true if the signal's name does not exist in its object, or the object is not valid." It appears to not describe the actual logic of the method. I experimented with it and someone pointed to me that the source code for this function is

# Callable.h
_FORCE_INLINE_ bool is_null() const {
	return method == StringName() && object == 0;
}

I don't really know how the engine source code is structured and can't verify that myself but here is the test I performed

var button : Button = Button.new()
var pressed_signal : Signal = button.pressed
button.free()
print(pressed_signal.is_null()) # Print false 

It seems like for the Signal.is_null() method to return true both the object and the signal name must be invalid, in my case the signal still has a name but is not attached to an object anymore

Here's the link to the method in the documentation : https://docs.godotengine.org/en/stable/classes/class_signal.html#class-signal-method-is-null

@AThousandShips
Copy link
Member

You're looking at the wrong method (though it's pretty similar):

_FORCE_INLINE_ bool is_null() const {
	return object.is_null() && name == StringName();
}

Still the exact description should be improved

@AThousandShips AThousandShips added area:class reference Issues and PRs about the class reference, which should be addressed on the Godot engine repository good first issue labels Aug 25, 2024
@AThousandShips
Copy link
Member

AThousandShips commented Aug 25, 2024

This should be fixed over in the main repo, and the easiest way is to just change the description to something like that of Callable.is_null, adjusted to fit Signal, though both could be improved slightly by clarifying that the method also has to be empty in Callable

I will write up a fix for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:class reference Issues and PRs about the class reference, which should be addressed on the Godot engine repository enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants