Godot: `variable is get_script()` no longer works

Created on 2 Jun 2020  路  7Comments  路  Source: godotengine/godot

Godot 3.2.2 beta 3

I migrated a game to Godot 3.2 and this broke:

func get_target_portal():
    var target_node = get_node(target_portal)
    assert(target_node != null)
    assert(target_node != self)
    assert(target_node is get_script()) # This line now fails
    return target_node
"is" test: the right operand isn't a type (neither a native type nor a script)

Apparently doing a is get_script() no longer works as it used to. It also doesn't work if I use load. I am also unable to use preload (which works in other cases) because it would be a cyclic reference.
Did I miss something about GDScript changes that could have broken this since 3.0.6 or is it a bug?

bug regression gdscript

Most helpful comment

Created a specific fix for this. Now get_script() return value is considered to be a valid type (the main class in the file).

All 7 comments

Can you check if variable is get_script() works in Godot 3.1-3.1.2 and 3.2-3.2.1? You could also try the 3.2 alphas/betas/RCs.

It works in Godot 3.2.1 and 3.2.2 beta1.
It starts breaking in 3.2.2 beta2.

CC @ThakeeNathees @vnen

It's not a regression, it always been a bug try print(node is get_script()) this will fail on previous versions too, but assert(node is get_script()) doesn't showed a parser error because the assert node arguments weren't reduced until bd081df51918a00f408845955d00dcbce2cea7a8 (try assert(bla_bla) on previous versions and they doesn't show anything on the editor).

and it has been fixed after 867d073b98344b848c96012418912a7e72841a31 by changing the return type of Object::get_script changed from RefPtr to Variant. @akien-mga maybe this could be backported to v3.2 ?

and it has been fixed after 867d073 by changing the return type of Object::get_script changed from RefPtr to Variant. @akien-mga maybe this could be backported to v3.2 ?

I doubt it, that's way too low level and it breaks compatibility.

Created a specific fix for this. Now get_script() return value is considered to be a valid type (the main class in the file).

Fixed by #39260.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Spooner picture Spooner  路  3Comments

bojidar-bg picture bojidar-bg  路  3Comments

mefihl picture mefihl  路  3Comments

testman42 picture testman42  路  3Comments

blurymind picture blurymind  路  3Comments