An interesting bug I have discovered

Godot Version

4.6.1

Question

I run this code and get this response any ideas?

extends CharacterBody2D

var character_attack_speed := 10.01

func _ready():
print(character_attack_speed)
character_attack_speed = 10.01
print(character_attack_speed)

Outputs:

1.0
10.01

Any ideas why my initial declaration doesn’t work? If I change the variable to character_attack_speed1 it works fine. If I comment out var character_attack_speed := 10.01 it errors. Its not getting changed anywhere else

When I copy your script and put it on a CharacterBody2D, the output is

10.01
10.01

as expected. Are you sure you’re not setting character_attack_speed anywhere?

By the way, the code will be more readable if you format it like this:
```gd
code
```

4 Likes

This tells me that it is indeed being changed somewhere else, maybe in another script, or some default you set somewhere else. It’s not a bug in Godot, but a bug in your game.

A good way to check if something is actually an engine bug or specific to your project is to create a completely new empty project, and ONLY add the lines of code you want to test.

2 Likes