Godot version
v4.0.alpha5.official [d7d528c]
System information
Ubuntu
Issue description
I'm aware we ought to use is_instance_valid() to validate an Object.
However in Godot 4 things may be a little different since comparison with null is now possible.
While [Freed Object] == null and not [Freed Object] was false in Godot 3, it is now true in 4.
However, [Freed Object] still validates to true in an if, while null validates to false.
This now results in very strange behavior:
var lele = Node.new()
lele.free()
if lele and not lele:
print("this prints")
or:
if lele == null:
print(lele, " is null")
if lele:
print(lele, " is true")
if not null:
print("null is false")
[Freed Object] is null
[Freed Object] is true
null is false
Many new users try comparison with null first before learning about is_instance_valid() (why this doesn't work in Godot 3 is a very common question). Since this yields the expected result now, they'll likely stick to it and never learn about is_instance_valid(). Treating [Freed Object] like null will however end up in users assuming if [Freed Object]: will validate to false, which it does not.
So here's the two solutions I can see (either or):
- Behavior of Godot 3 should be restored
- Meaning
[Freed Object] == null and not [Freed Object] should both be false again
if [Freed Object]: should validate to false as well
- Which would reduce complexity as we could actually do away with
is_instance_valid()
Steps to reproduce
Run example code in a _ready function.
Minimal reproduction project
No response
Godot version
v4.0.alpha5.official [d7d528c]
System information
Ubuntu
Issue description
I'm aware we ought to use
is_instance_valid()to validate an Object.However in Godot 4 things may be a little different since comparison with
nullis now possible.While
[Freed Object] == nullandnot [Freed Object]was false in Godot 3, it is now true in 4.However,
[Freed Object]still validates to true in an if, whilenullvalidates to false.This now results in very strange behavior:
or:
Many new users try comparison with null first before learning about
is_instance_valid()(why this doesn't work in Godot 3 is a very common question). Since this yields the expected result now, they'll likely stick to it and never learn aboutis_instance_valid(). Treating[Freed Object]likenullwill however end up in users assumingif [Freed Object]:will validate to false, which it does not.So here's the two solutions I can see (either or):
[Freed Object] == nullandnot [Freed Object]should both be false againif [Freed Object]:should validate to false as wellis_instance_valid()Steps to reproduce
Run example code in a
_readyfunction.Minimal reproduction project
No response