godotengine / godot

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

Clarify documentation: Overriding Class Functions vs Setters and Getters #29390

Open TheDuriel opened 5 years ago

TheDuriel commented 5 years ago

Godot version:

3.1.1

OS/device including version:

Any

Issue description:

func set_default_color(new_value: Color) -> void:
    print("hey")
    default_color.a = 0.0

In a tool script on a Line2D Node results in nothing. No printing, no color change.

Steps to reproduce: ^

Minimal reproduction project:

TheDuriel commented 5 years ago

So, after some further discussion in discord. This is not a bug, no setters and getters are overridable if the property is not declared by the user. However, this begs the question of poor documentation. Class functions are overridable in all cases. and the original can be called in .. Setters and Getters are documented in the same manner, but are also entirely pointless since they are not overridable. There may be some hacky way to do it by overriding set and get, but thats a really bad solution if it even works.

TheDuriel commented 5 years ago

@KoBeWi Since you're around. Can you redo the tags please?

henriiquecampos commented 5 years ago

Is there anyway to at least add a warning to the Editor's warnings to communicate this in any manner? Like when we use set_* it will search in the ClassDB if this method is a built-in setter/getter and automatically warn that Built-in setter and getter functions are not overridable, then the person can decide if they want to create their own.

bojidar-bg commented 5 years ago

Even better: warn when a script overrides a function present in the base class which isn't marked "virtual". That way people overriding e.g. CanvasItem.update would be warned.