Variable Stuck even after Restart

Godot Version

4.7

Question

Hi there, I came across the strangest bug. It has happened to me twice now.

I am currently trying to program a First Person Controller. I have acceleration and deceleration in it. I was tweaking it and noticed that when I change my acceleration value, even to a ridiculously high value, it doesn’t actually change.

Here in the code, I have it initialized as 20000000000, but when I print the value of acceleration, it only outputs 1.0.

Only when I change the name of the variable (and I changed the name of acceleration throughout the whole code) does it change to the value I initialized.

This happened to me before in the same file, but with jump force. I had to rename it to jumpVelocity (better name anyway).

extends CharacterBody3D

@onready var camera_controler: Node3D = $CameraControler


@export var maxSpeed:float = 10
@export var sprintMultiplier:float = 2
@export var airSpeedMultiplier:float = 0.01


##Accelartationin steps
var acceleration:float = 20000000000
@export var airAcceleration:float = 66
@export var decceleration:float = 100


@export var jumpVelocity:float = 8
@export var jumpGravityModifier:float = 1
@export var fallGravityModifier:float = 3
@onready var gravity:Vector3 = get_gravity()

@export var mouseSensitivity:float = 0.005

var mouseCameraInput:Vector2

enum States {Idle,Walking, Running, Jumping, inAir}
	
var state = States.Idle
var stateBefore = state

func changeState(newState) -> void:
	state = newState


func _ready() -> void:
	Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
	print(acceleration)


this outputs 1.0

extends CharacterBody3D

@onready var camera_controler: Node3D = $CameraControler


@export var maxSpeed:float = 10
@export var sprintMultiplier:float = 2
@export var airSpeedMultiplier:float = 0.01


##Accelartationin steps
var acceleration2:float = 20000000000
@export var airAcceleration:float = 66
@export var decceleration:float = 100


@export var jumpVelocity:float = 8
@export var jumpGravityModifier:float = 1
@export var fallGravityModifier:float = 3
@onready var gravity:Vector3 = get_gravity()

@export var mouseSensitivity:float = 0.005

var mouseCameraInput:Vector2

enum States {Idle,Walking, Running, Jumping, inAir}
	
var state = States.Idle
var stateBefore = state

func changeState(newState) -> void:
	state = newState


func _ready() -> void:
	Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
	print(acceleration2)

this outputs the 20000000000.When i change it back acceleration it outputs 1 again.

it might be usefull to know that acceleration was an @export value before.

Does anybody have an idea what the issue could be?

Is there a an editor warning or errors?

May have something to do with editor caching.

Close the project exit Godot, make backup and delete the hidden .godot cache folder for that project. Reopen.

Nope no errors, i will try deleting the cache golder in the evening as i am currently at work.

The scene file must still have a line for acceleration = 1.0, maybe re-opening the scene could fix this it’s usually removed automatically, but you are correct that there is some latent data. You could edit the scene file manually to remove that line, .tscn files are easy to read and write as just text.

Ok found it.

It was in the parent scene world.tscn (second last entry)

[gd_scene format=3 uid="uid://c1u6kbvq8k31"]

[ext_resource type="Texture2D" uid="uid://caujcpbkh8q3k" path="res://Debug texture.png" id="1_f3sb7"]
[ext_resource type="PackedScene" uid="uid://cyeao06at0ryg" path="res://player_controler.tscn" id="2_fj7yv"]

[sub_resource type="BoxMesh" id="BoxMesh_x4bid"]
size = Vector3(50, 1, 50)

[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_fj7yv"]
albedo_color = Color(0.6362561, 0.3960012, 0.11311539, 1)
albedo_texture = ExtResource("1_f3sb7")
uv1_scale = Vector3(10, 10, 10)
texture_filter = 0

[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_fj7yv"]
data = PackedVector3Array(-25, 0.5, 25, 25, 0.5, 25, -25, -0.5, 25, 25, 0.5, 25, 25, -0.5, 25, -25, -0.5, 25, 25, 0.5, -25, -25, 0.5, -25, 25, -0.5, -25, -25, 0.5, -25, -25, -0.5, -25, 25, -0.5, -25, 25, 0.5, 25, 25, 0.5, -25, 25, -0.5, 25, 25, 0.5, -25, 25, -0.5, -25, 25, -0.5, 25, -25, 0.5, -25, -25, 0.5, 25, -25, -0.5, -25, -25, 0.5, 25, -25, -0.5, 25, -25, -0.5, -25, 25, 0.5, 25, -25, 0.5, 25, 25, 0.5, -25, -25, 0.5, 25, -25, 0.5, -25, 25, 0.5, -25, -25, -0.5, 25, 25, -0.5, 25, -25, -0.5, -25, 25, -0.5, 25, 25, -0.5, -25, -25, -0.5, -25)

[node name="World" type="Node3D" unique_id=1504694127]

[node name="MeshInstance3D" type="MeshInstance3D" parent="." unique_id=1120643116]
mesh = SubResource("BoxMesh_x4bid")
surface_material_override/0 = SubResource("StandardMaterial3D_fj7yv")

[node name="StaticBody3D" type="StaticBody3D" parent="MeshInstance3D" unique_id=249643542]

[node name="CollisionShape3D" type="CollisionShape3D" parent="MeshInstance3D/StaticBody3D" unique_id=1932125673]
shape = SubResource("ConcavePolygonShape3D_fj7yv")

[node name="PlayerControler" parent="." unique_id=2069674927 instance=ExtResource("2_fj7yv")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -21.92294, 2, -19.871244)
acceleration = 1.0

[node name="DirectionalLight3D" type="DirectionalLight3D" parent="." unique_id=645320976]
transform = Transform3D(1, 0, 0, 0, 0.7874367, 0.45328444, 0, -0.838201, 0.7874367, 0, 33, 0)

I delete the line acceleration = 1.0 and it works now.

Any idea how this could Happen?

I would rather not waste my time tweaking without realising its not changing anything ^^

Thank you so much :heart:.

How it happened makes sense, @export and editing the property produces that line in the scene file. The scene file is not updated (or will be updated on next open) when the script removes the @export tag.

Preventing this is tough, I’d try not to change @export variables and their names too often, or be very thorough checking they are still valid. Expect all references to break when editing these, it is impossible to track from Godot’s point of view. Take for example the jumpForce changed to jumpVelocity, Godot cannot tell this is a name change, it only sees a variable was removed and a variable was added, so all of the jumpForce data is deleted or dead and in the files and jumpVelocity is brand new, so it has no data.