Using @export_category using the same name as a variable will overwrite the first variable in the category.
Godot version
4.0.2.stable.mono
System information
Windows 10 - 4.0.2.stable.mono - Any Renderer
Issue description
In a script with an @export variable (with a non-default value), Godot will replace the first variable in the category with the same name. For example, if you're exporting a variable called "Vector", and the value is set to a non-default value, the first variable in the category called "Vector" will also be changed to the same value.
Steps to reproduce
Attach said script to a node:
extends Node
@export var Vector: Vector2
@export_category("Vector")
@export var Var2: float = 1
func _process(delta):
print(Var2)
When changing the value of the Vector export variable, the variable Var2 will contain the same value. This does not happen when the @export_category has a different name.
Minimal reproduction project
N/A
Also reproducible on 4.0.3.stable for me.
Also occurs when using @export_group and @export_subgroup in place of @export_category
Should having a same variable name as a category be allowed in the first place (especially with the same casing)? To me, this seems like something that could confuse developers and users alike.
Should having a same variable name as a category be allowed in the first place (especially with the same casing)? To me, this seems like something that could confuse developers and users alike.
I would have expected categories and variable names to not affect each-other at all, and simply be for organization in the editor, since besides this they don't really change anything in the code. This came up when I had an import for Camera, and I also had a group for camera settings also called "Camera", and my sensitivity property was being overwritten by my Camera object.
The way groups and categories are implemented is such that they are also properties, albeit with special flags. Which is how you can define them with the _get_property_list override. So this is indeed an expected limitation.
This should be better documented then.
It should script error, like defining any other variable twice does
I disagree, for me category/group/subgroup names are just text that shouldn't interfere with variables and classes. It is logical that you can use the same subgroups in different groups.
Also the documentation says that you can use @export_group("") to end the current group. In the current implementation, you can only do this once, otherwise bugs occur (see #68030). "" is a real property or just text?
See https://github.com/godotengine/godot/pull/78254#issuecomment-1598571931.