GodotModding / GodotModding/godot-mod-loader

Hooked scripts aren't stopped when their vanilla script exits the scene tree

Open
#595 0 comments 0 reactions 0 assignees View on GitHub
4.x investigate
Dominant language
GDScript
Stars
675
Forks
54
Avg merge
2m
Merged PRs (30d)
2

Description

Godot Version: **4.1.1**
Mod Loader Version: **7.0.1**

I found an issue with hook behavior during scene transitions; I was asked in the Discord to put this here just as a reminder.

Let's say that I have this base function:
```
var some_variable = false

func EndRound():
await get_tree().create_timer(5).timeout
print("You win!")
await get_tree().create_timer(5).timeout
print("awarding points")
await get_tree().create_timer(5).timeout
```
and I hook it like this:
```
func EndRound(chain: ModLoaderHookChain):
var baseClass = chain.reference_object
await baseClass.get_tree().create_timer(5).timeout
print("You win!")
await baseClass.get_tree().create_timer(5).timeout
print("awarding points")
baseClass.some_variable = true
await baseClass.get_tree().create_timer(5).timeout
```
If I end up changing scenes while the hook is running, I'll get an error that some_variable doesn't exist in base class nil (previously freed). The mod loader doesn't currently have a built-in way to stop execution of these hooks, whereas I believe it does for extensions. This isn't causing issues for me per se, but I foresee it being a problem if the hook has access to a node outside the current scene (such as a mod_main).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.