• Godot Help
  • Can I attach an autoload script to a node and reference its children?

Im trashing around and maybe the reason I cant seem to get to work $Camera2D.make_current() or $Sprite2D.visibility=true (examples) is because I'm attaching an autoload script to the Node Parent of my scene, since if I attach a non-autoload script with the same code the children work without any issues.

  • Jesusemora replied to this.
  • The_fail no. you define your autoloads in project settings. an autoload runs OUTSIDE the scene, don't try to add it to a node.
    the advantage of an autoload is that:
    1 - it runs outside the scene, so you can use it to store data between levels and load levels.
    2 - you can access it from any script by name. I use one to store scenes and materials like bullets, explosions and enemies and spawn them in the scene.

    You can not attach an autoload script to a node. This would just break everything. Autoloads are supposed to sit at the root of the scene tree.

    The_fail no. you define your autoloads in project settings. an autoload runs OUTSIDE the scene, don't try to add it to a node.
    the advantage of an autoload is that:
    1 - it runs outside the scene, so you can use it to store data between levels and load levels.
    2 - you can access it from any script by name. I use one to store scenes and materials like bullets, explosions and enemies and spawn them in the scene.

    DaveTheCoder
    Well I'm a beginner at GODOT, but autoloads seem very usefull.
    I have one autoload where I store data that different scenes will edit in every level, I dont really know any easier alternatives.
    My autoload also has slow-mo functions so any scene can call them.