pkdawson/imgui-godot

cannot change values wuth ImGui

Opened this issue · 4 comments

i use this following code to change some values that will be important for me to debug on

var player = null
func _DEBUG_UI(delta):
	if player != null:
		ImGui.Begin("DEBUG_GUI")
		ImGui.DragFloat("Vehicle Dirtyness", [player.dirtyness])
		ImGui.DragFloat("Vehicle Engine Health", [player_health_engine])
		ImGui.DragFloat("Vehicle Body Health", [player_health])
		ImGui.End()

the problem is none of these values do change no matter what i do, those values arent controlled by anything else unless there is some circumstances for example engine health reduces only if my player's vehicle goes over its RPM capacity (an V8 going over 10krpm)

no matter what i do those values never change

See #73 (comment)

I really need to reorganize and expand the docs to clarify some common issues.

I found out my way out with this method tho

var imgui_value_number := [something]

In function:
   ImGui.dragfloat("something", imgui_value_number)
   If GameManager.Brute_Update:
      My_actual_value = imgui_value_number[0]

This is kinda something but good enough for me
This can be helpful for those who can't modify their var to be array since that variable is possibly being used by alot of code making the things harder for them

I faced a similar issue while trying to set up a debug menu.

Here, I'm trying to update a variable stored in a Global autoload.
It seems that setters aren't called :

var menu_is_open: bool = false

var debug_overlay_enable = [false]:
	set(value):
                # This is never reached
		print("Changing value..."])
                # "Global" is an autoload
		Global.game_settings.debug_overlay_enable = value[0]
		debug_overlay_enable = value


func _input(event: InputEvent) -> void:
	if event.is_action_pressed("open_debug_menu"):
		menu_is_open = not menu_is_open


func _process(_delta: float) -> void:
	if menu_is_open:
		ImGui.Begin("Debug menu")
		ImGui.Checkbox("Enable debug overlays", debug_overlay_enable)
		ImGui.End()

As suggested by @sinaSPOGames, manually updating the variable works, but is not very elegant :

extends Node

var menu_is_open: bool = false

var debug_overlay_enable: Array = [false]

# func _input [...]

func _process(_delta: float) -> void:
	if menu_is_open:
		ImGui.Begin("Debug menu")
		ImGui.Text("Hello world !")
		ImGui.Checkbox("Enable debug overlays", debug_overlay_enable)
		ImGui.End()

	        Global.game_settings.debug_overlay_enable = debug_overlay_enable[0]

... and it still requires creating a variable.

It would be great to have an easier way of binding the value of ImGui controls to existing variables !

(and I'm glad you're considering improving the docs, that's always appreciated)

one thing can be done is adding a unique way to access variables

in imgui's base code instead of requiring the ImGui.example(example, example[0]) just do the second identifier in code
it can check wether its a normal variable or just an array, if normal variable then convert it into a unique array variable and use that to set the actual variable, by this way we dont have to creating a variable just for this