SpyrexDE / SmoothScroll

Addon for the Godot Game Engine that adds a SmoothScrollContainer.
https://spyrexde.github.io/SmoothScroll/
MIT License
132 stars 10 forks source link

SmoothScrollContainer script errors randomly on initialization: ParserError: Could not find "ScrollDamper" in the current scope #51

Open ReikaKalseki opened 2 months ago

ReikaKalseki commented 2 months ago

As seen here:

Thrown by this line of code, which is switched to and highlighted when the error occurs:

I have not seen any identifiable cause for the error, as when the error occurs I can just try again and it usually works (only to error again later). The only pattern I have been able to identify is that I have yet to see it error in two successive attempts. (This is not to say it errors every second attempt; it can go 2, 5, 13, or any other number of initializations between errors).

This is with the newest version of the plugin (downloaded yesterday) and the newest Godot as of a month ago, 4.2.1.

SpyrexDE commented 2 months ago

This issue is probably related to https://github.com/godotengine/godot/issues/78642. I tried adding the ScrollDamper as a custom type in the last commit but I am not sure if it helps with this issue. One thing you could try is deleting the .godot directory.

ReikaKalseki commented 2 months ago

One thing you could try is deleting the .godot directory.

Would that not brick my own project?

SpyrexDE commented 2 months ago

Would that not brick my own project?

No, the .godot directory only contains cache data. (docs)

ReikaKalseki commented 2 months ago

Would that not brick my own project?

No, the .godot directory only contains cache data. (docs)

In fact it did, due to some straggling cached files, but I was able to fix it.

However, this did not fix the issue on initialization.

HaroldLever commented 2 months ago

There is a temporary solution. Open any script file (not built-in script) in Godot script editor, press "File-Save" or "File-Save all". It will force update all class cache.

HaroldLever commented 2 months ago

This might be a bug of Godot engine, for lots of users have raised issues of missing classes, especially for those classes in plugin.

You can try the code below which might fix your problem temporarily.

@tool

extends EditorScript

const cache_file_path := "res://.godot/global_script_class_cache.cfg"

const class_cache := [
    {
    "base": &"ScrollDamper",
    "class": &"CubicScrollDamper",
    "icon": "",
    "language": &"GDScript",
    "path": "res://addons/SmoothScroll/scroll_damper/cubic_scroll_damper.gd"
    }, {
    "base": &"ScrollDamper",
    "class": &"ExpoScrollDamper",
    "icon": "",
    "language": &"GDScript",
    "path": "res://addons/SmoothScroll/scroll_damper/expo_scroll_damper.gd"
    }, {
    "base": &"ScrollDamper",
    "class": &"LinearScrollDamper",
    "icon": "",
    "language": &"GDScript",
    "path": "res://addons/SmoothScroll/scroll_damper/linear_scroll_damper.gd"
    }, {
    "base": &"ScrollDamper",
    "class": &"QuadScrollDamper",
    "icon": "",
    "language": &"GDScript",
    "path": "res://addons/SmoothScroll/scroll_damper/quad_scroll_damper.gd"
    }, {
    "base": &"Resource",
    "class": &"ScrollDamper",
    "icon": "res://addons/SmoothScroll/scroll_damper/icon.svg",
    "language": &"GDScript",
    "path": "res://addons/SmoothScroll/scroll_damper/scroll_damper.gd"
    },
]

func _run() -> void:
    refresh()

func refresh():
    if not Engine.is_editor_hint(): return

    var global_class_list = ProjectSettings.get_global_class_list()
    var cache_file = ConfigFile.new()
    cache_file.load(cache_file_path)

    for item in class_cache:
        global_class_list.append(item)

    cache_file.set_value("", "list", global_class_list)
    cache_file.save(cache_file_path)

Please create a new GDScript file in your project and paste the code above, then run the editor script. Tutorial

If you had moved this plugin to another path, please modify path in class_cache to ensure script files' path are correct.