Godot version:
3.0.2
OS/device including version:
Win 10
Issue description:
It would be very convenient to override certain default functions, specifically getters and setters. Apparently this is not possible now, and I have tried doing so with set_global_rotation and set_wait_time to no avail.
My current workaround is to create a set_wait_time function and only every use it to update the built in vars. But this is messy/easy to forget/hard to maintain.
What use case do you want this for? Keep in mind that means the engine would have to check, for every function called, if a function of the same name exists in the script and call that instead... (I.e in C++ you would never do set_position anymore, but call("set_position") all the time. Performance may suffer for all nodes, even with no script attached.
Even in regular library codebases it's rare to see the entirety of functions being virtual. Functions are virtual when they are expected to be, otherwise they don't.
See also #17218
Use cases:
set_global_rotation: rotate the node and all its children, except for child A, B, and C. Those should always be 0 deg rotation. So override and set those children's rotation to 0 when the parent's rotation changes.set_wait_time: A TextureProgress indicates to the user how much time is left in this timer. When wait_time changes, I want to change my_texture_progress.max_value too.Do we know this would impact performance, or is this an assumption? If it's a large performance hit then definitely not worth it, as the increase in ease of use/maintainability is relatively minor in comparison.
Since this has come up multiple times (that we know of) it should probably be written down somewhere, either in the docs or on a roadmap (to investigate).
It's not an assumption. Since those functions can't be overriden, the C++ code just calls the C++ functions. If they could, it'd have to look for the functions instead, and interpret the GDScript code. The engine code doesn't use them often or at all, but game code does.
Definitely don't want to do that I would think. Where do you think this should be documented?
this could be used to allow making custom container control nodes.
basically you override the child being added and cancel it and instead add a item to the node in your scene. for example a internal vbox container.
however something like my example would also need a way to forward your nodes back to the scene
I think I found a good solution. You see, there's this function called _set. it get's called whenever a value gets set. What you can do is create your setter, then in the _set method, check if that value is being set, and if so, call your setter.
func _set(property : String, value) -> bool:
if property == "material_override":
set_material_override(value)
return true
return false
func set_material_override(value : Material) -> void:
material_override = value
# Do other things with it.
I'll close this, since this is already supported as @SIsilicon demonstrated it.
What would that look like in C#?
@JarLowrey I believe _Set can be overridden in C#, or can it? If this is the case, then you just need to override the method as you would override _Ready or any other virtual function.
Most helpful comment
I think I found a good solution. You see, there's this function called
_set. it get's called whenever a value gets set. What you can do is create your setter, then in the_setmethod, check if that value is being set, and if so, call your setter.