Open wyattbiker opened 3 years ago
As a workaround, you can yield for a frame in gui_input callback method.
func _on_VSlider_gui_input(event: InputEvent) -> void:
if (event.is_pressed() and event.button_index == BUTTON_LEFT):
yield(get_tree(),"idle_frame")
print("\nClicked")
print("_gui_input: ",value) # Reports the old slider value```
Does this occur with other kinds of GUI controls such as CheckBox?
This may actually be intended behavior, but I'm not 100% sure. Sometimes, you actually want to read the old value of a control. Maybe it should just be documented.
yield(get_tree(),"idle_frame")
@jmb462 Good workaround as long as you don't mind value_changed()
being completed before gui_input().
@Calinou As per your suggestion CheckBox
as well as SpinBox
have same behavior as VSlider
. Would be nice to understand if it's a use case and document it with workaround and leave alone. I assume so much software been written around it.
In my case I was using gui_input()
to emit a signal to other scenes that used that control. So it was providing the 'old' value to them.
I think it wouldn't really make any sense to keep the old value on _gui_input()
. If I needed the old value, I would of just made a variable called var last_value
and set it to whatever value comes through _gui_input()
or _value_changed()
.
The Control node first calls the virtual function Control._gui_input
, allowing you to manually handle input before it's processed internally.
void Control::_call_gui_input(const Ref<InputEvent> &p_event) {
if (p_event->get_device() != InputEvent::DEVICE_ID_INTERNAL) {
emit_signal(SceneStringName(gui_input), p_event); // Signal should be first, so it's possible to override an event (and then accept it).
}
if (!is_inside_tree() || get_viewport()->is_input_handled()) {
return; // Input was handled, abort.
}
if (p_event->get_device() != InputEvent::DEVICE_ID_INTERNAL) {
GDVIRTUAL_CALL(_gui_input, p_event);
}
if (!is_inside_tree() || get_viewport()->is_input_handled()) {
return; // Input was handled, abort.
}
gui_input(p_event);
}
Godot version: Godot Engine v3.2.4.rc4.official - https://godotengine.org OpenGL ES 3.0 Renderer: NVIDIA GeForce GT 650M OpenGL Engine OpenGL ES Batching: ON Mac OS X Catalina 10.15.7
Issue description: VSlider reports old value of slider in
_gui_input(event: InputEvent)
signalSteps to reproduce:
VSlider
ControlWhen
VSlider
is clicked_gui_input()
method reports the original old value, while_value_changed()
reports the correct new value.Example Output:
Makes the _gui_input() not as useful.
Thanks!