godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.16k stars 20.21k forks source link

Exported values stuck at default even when changed in inspector #95573

Open Xkonti opened 1 month ago

Xkonti commented 1 month ago

Tested versions

System information

Windows 11; Godot 4.3-stable; Forward +

Issue description

I have code that has several exported variables:

@export_group("Assists")
## The coyote time duration in seconds.
## The player will be able to jump for this extra amount of time after
## stopped touching the ground. It reduces the risk of the player falling off the platform
## when intended to jump.
@export_range(0.0, 1.0) var coyote_duration: float = 0.1

## Display the coyote timer debug label.
@export var debug_coyote: bool = false

The problem didn't occur initially. Now, when I change the exported value in the editor (inspector), it doesn't update during gameplay. Interestingly, it does update the value in the scene file.

image

During gameplay I added a quick debug print:

func start_coyote(delta):
    print("Starting coyote with duration of %.3fs" % coyote_duration)
    print("Delta is %.3fs" % delta)
    var time_left = coyote_duration - delta
    print("Time left is %.3fs" % time_left)
    coyote_timer.start(time_left)
    is_coyote = true
    coyote_started.emit()

Even though the value is set to 0.28 in the scene, during runtime the value shows as the default 0.1:

Starting coyote with duration of 0.100s
Delta is 0.017s
Time left is 0.083s

The same goes for the checkbox and other values. They seem to stop reacting to changes in the editor.

Steps to reproduce

Not sure how to reproduce as this worked flawlessly for a while and then out of nowhere it stopped working without making any related code changes.

Minimal reproduction project (MRP)

The whole project is available at GitHub (including assets): https://github.com/Xkonti/PlatformerToolkitGodot

SuzukiStumpy commented 1 week ago

I've also come across this with simple base variable types.

For example, I have a character scene that has a script containing the following:

@export var is_player: bool
@export var cur_hp: int = 25
@export var max_hp: int = 25

None of the rest of the code sets the values for these variables except to update them in response to actions. Now, in my main scene, I have several instances of these Character objects, with different values set for the cur_hp and max_hp in their respective inspector panels, yet when I launch the game, all of them revert to the default values of 25.

Also, saving, exiting and relaunching Godot doesn't make any difference, so this appears to be persistent. If, however, I remove the default values from within the script and simply assign values in the inspector alone, then everything seems to work fine.

(using Godot 4.3 Stable)