Skip to content

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

Description

@MSLaFaver

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions