Variable values updating without reason

Godot Version

4.6 Stable

Question

I have this piece of code, that no other part of the project touches.
Somehow godot is trying to reassign my variables to -0.5 and 0.5 respectively (values that I started with previously but apparently can’t change now, I’ve tried many combinations of values but it keeps outputing the same)
I had to use to setters to keep the base values, but used the print function to see if I was going crazy:

var min_pitch: float = -0.05: # Looking down
	set(value):
		min_pitch = -0.05
		print("min_pitch was changed to ", value)
var max_pitch: float = 0.05: # Looking up
	set(value):
		max_pitch = 0.05
		print("max_pitch was changed to ", value)

output:
min_pitch was changed to -0.5
max_pitch was changed to 0.5

Maybe you have clamped it elsewhere in the code. Check for clamped values.

Maybe it helps to add get_stack() to your print(), to see from where the value gets changed. Or just use a breakpoint.

1 Like

I added get_stack() and it apears to be from the setter, somehow (I even tried on a different PC). The output:
min_pitch was changed to -0.5 by [{ “source”: “res://Scripts/camera_controller.gd”, “function”: “@min_pitch_setter”, “line”: 11 }]
max_pitch was changed to 0.5 by [{ “source”: “res://Scripts/camera_controller.gd”, “function”: “@max_pitch_setter”, “line”: 15 }]

That’s pretty strange. Are you sure these variables aren’t and weren’t @exportvariables, and the value is changed via the inspector?

I would also check AnimationPlayers (if you have any), if min_pitch and max_pitch somehow ended up in the RESET track with those values.

Nowhere in the project does this get changed, I know that because I just created this script from scratch

They were @export but because of that “bug” (IDK what to call it) I removed the @export, even tho the values in the inspector were not -0.5 / 0.5

In that case, why no just set the values in a different way? And clamp them to the max/min-values you want.

I have solved the problem by using the setters (a bad solution, I know, would be better to use the ready func). I posted it here because it makes no sense to me and I was hoping someone would illuminate me or tell me this is actually a known bug or idk XD

If your scene is a text scene (.tscn), you could look inside if somewhere in it the min_pitch and max_pitch are overridden. It’s a curious case.

EDIT: If you have a minimal test case you could upload your project and I’d like to have a look.