godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.28k stars 21.05k forks source link

Type hinting with signals produces unintended behaviour. #27969

Closed EMBYRDEV closed 5 years ago

EMBYRDEV commented 5 years ago

Godot version: 3.1 stable

OS/device including version: Windows 10 64bit

Issue description: When type hinting is used with signals some weird behaviour occurs, the following code is valid and works perfectly fine.

However when type hinting is added it throws the following error when run.

But when I add a null check to the function body the code works again and also fires off properly when the player enters the spikes.

I have checked the built in help which confirms that body is indeed of type PhysicsBody2D

This suggests to me that possibly something that isn't a PhysicsBody2D is being passed to the function by mistake?

Minimal reproduction project: Reproduction project (Metroidvania.zip)

EMBYRDEV commented 5 years ago

Apparently typeof() produces the number 17 which is apparently type object and not PhysicsBody2D...

Also the problem is solved if I move the spikes scene up off the tilemap so that it's not colliding which tells me the collision with the Tilemap is passing an Object to body_entered and not a PhysicsBody2D as the documentation suggests... not sure if this is intentional or not?

kaadmy commented 5 years ago

Just to be clear, typeof returns an enum value from the TYPE_* global enum, which is not the class name of the object.

Duroxxigar commented 5 years ago

I was able to reproduce this issue. I don't think this is intended functionality either. While technically, it is true that a collision happened, it just seems odd that you wouldn't be able to use static typing if you're using a tilemap. Perhaps have a toggle to allow the user decide if a tilemap should generate body_entered events or not.

akien-mga commented 5 years ago

Duplicate of #27076.