godotengine / godotengine/godot

"Class hides a global script class" script parsing issue

Open
#94,378 10 comments 1 reaction 0 assignees View on GitHub
discussion documentation topic:gdscript
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

v4.3.beta3.official [82cedc83c]

### System information

Godot v4.3.beta3 - EndeavourOS #1 SMP PREEMPT_DYNAMIC Wed, 12 Jun 2024 20:17:17 +0000 - X11 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 2080 SUPER (nvidia; 550.90.07) - Intel(R) Core(TM) i5-8400 CPU @ 2.80GHz (6 Threads)

### Issue description

In certain cases, you might decide to remake or otherwise archive a script, but still keep it in the project files in the original place. Usually all you need to do is rename the script to something to indicate it's archive or backup status. This isn't a problem normally, UNLESS you use the `class_name` declaration and want to keep the same name from the old script to the new one. Godot parses ALL scripts regardless of their actual use, so as a result, when two scripts declare the same `class_name` it fails to parse the script and breaks the game. This may be the intended behavior, but IMO, it shouldn't be parsing ALL scripts, but instead ONLY the scripts that will actually be ran.

EDIT: For my personal game project, this behavior doesn't seem to start until 4.2, and 4.3 makes it even more picky. Under 4.1.4, there is no issue in my game. However, I'm not sure what the reason is, and the only differences I see from the MRP are that my scripts are in subfolders, and the difference between 4.2 and 4.3 for my game is that 4.2 didn't have issue with scripts with the same name in different folders even with the same class_name, while 4.3 does have issue.

### Steps to reproduce

Create a script attached to a node.
Use the `class_name` declaration in this script.
Duplicate the script with a different name.
Parse error.

### Minimal reproduction project (MRP)

[global_script_class_issue.zip](https://github.com/user-attachments/files/16229931/global_script_class_issue.zip)

Contributor guide

Open the contributing guide

Research direction

Start with the attached global_script_class_issue.zip MRP and reproduce the parse error by duplicating a script that declares class_name. Compare the reported behavior across the mentioned Godot versions and determine the intended handling of duplicate global script classes; done means the reproduction no longer breaks unexpectedly with the agreed behavior.

Written by the indexing model from the issue text.

Assessment

Domain
compilers, game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.