mogoh
December 21, 2023, 2:05am
1
Godot Version
4.2.1
Question
Hello.
This is a reduced version of my setup:
/tests/debug.gd
class_name DebugTool
extends Node
static func print(x: Variant) -> void:
if OS.is_debug_build():
print(x)
/global/network.gd
This is loaded as singleton.
extends Node
#[...]
# this get called on the server and clients
func _peer_connected(peer_id: int) -> void:
DebugTool.print("Peer connected with id: " + str(peer_id))
#[...]
This works fine on my desktop.
However, if I build my project on CI I get this error:
[...]
SCRIPT ERROR: Parse Error: Identifier "DebugTool" not declared in the current scope.
at: GDScript::reload (res://global/network.gd:18)
[...]
Is there something wrong with my script?
Is this a bug?
If this is a bug, has it been reported?
jariw2
December 21, 2023, 7:15am
2
Is the singleton stuff called by the _ready() function? That could be a potential culprit.
mogoh
December 21, 2023, 10:22am
3
I am not sure, what you mean.
The /global/network.gd
has a _ready
-function.
Here is how it looks like:
func _ready() -> void:
multiplayer.connected_to_server.connect(_connected_to_server)
multiplayer.connection_failed.connect(_connection_failed)
multiplayer.peer_connected.connect(_peer_connected)
multiplayer.peer_disconnected.connect(_peer_disconnected)
multiplayer.server_disconnected.connect(_server_disconnected)
mogoh
December 21, 2023, 10:52am
4
I reduced everything to a minimal project:
GitLab.com
Here is an example output of the ci pipeline:
GitLab.com
jariw2
December 21, 2023, 2:08pm
5
If you comment out this line (or skip all the 5 lines in the _ready() function), does the error message disappear?
mogoh
December 21, 2023, 3:03pm
6
It does not help, but I think I could reduce the problem more and I think it is a bug.
I will create a bugreport and link it here.
The problem is that the file .godot/global_script_class_cache.cfg
not generated at first and that is somehow a problem.
mogoh
December 21, 2023, 3:21pm
7
There is already an issue open:
opened 11:16AM - 27 Mar 23 UTC
bug
topic:gdscript
topic:editor
### Godot version
4.0, 4.0.1
### System information
Windows 11/64, RTX … 3070, Vulkan
### Issue description
This will break our game and give hundreds of errors without our workarounds. It appears that autoloaded scripts are loaded before `global_script_class_cache.cfg` is populated, yet Godot only loads class names from that file. So, if a class isn't registered in the file, the autoload fails.
```gdscript
# ItemDB.gd: <- Autoloaded
extends Node
var stats: Stats
func _ready():
Util.test()
```
```gdscript
# Stats.gd
class_name Stats
extends Resource
```
```gdscript
# Util.gd
class_name Util
static func test():
pass
```
Autoload ItemDB.gd, then close Godot, delete `global_script_class_cache.cfg` and reload. It will break with these errors:
```
SCRIPT ERROR: Parse Error: Could not find type "Stats" in the current scope.
at: GDScript::reload (res://ItemDB.gd:3)
SCRIPT ERROR: Parse Error: Identifier "Util" not declared in the current scope.
at: GDScript::reload (res://ItemDB.gd:6)
ERROR: Script does not inherit from Node: res://ItemDB.gd.
at: (editor/editor_autoload_settings.cpp:423)
```
Stats and Util are two examples of the same problem. They can be tested independently. It is also an issue with any derivative classes. If ItemDB has an Item, which has a Stats, which is our set up, this also causes the issue.
It's not just a problem with an empty cache file. If someone on a team makes a change to these classes and saves the new class locally, those changes will not get to other team members via git, because Godot does not generate the new cache properly. We have some autoloaded base classes, so when this breaks, we get hundreds of error messages across many scripts.
Workarounds include:
* Manually open each gdscript file in Godot and resave without changes, one at a time. This will populate the local `global_script_class_cache.cfg`. Opening all, then saving all does not do it.
* Copy `global_script_class_cache.cfg` from another computer or store it in git. We ended up doing the latter to work around this bug.
This bug has been present for a long while. We worked around it for a while, but finally discovered the exact circumstances today.
In my game, I have received this error message, though I don't get it in the MRP or while debugging. It may provide a clue:
```
ERROR: Condition "!base->is_valid() && !base->reloading" is true. Returning: ERR_BUG
at: _populate_class_members (modules/gdscript/gdscript_compiler.cpp:2318)
```
### Steps to reproduce
See above
### Minimal reproduction project
[test_gdscript_cache.zip](https://github.com/godotengine/godot/files/11077941/test_gdscript_cache.zip)
_Bugsquad edit: used syntax highlighting for example gdscript code_
system
Closed
January 20, 2024, 3:21pm
8
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.