Godot Version
v4.7.2.stable.official
Question
I want to have a global autoload function which attaches and detaches scenes from nodes within a main tree that never changes. For example, there is a MainMenu node which can be moved around freely, and its child, a MainMenu root node which serves as an anchor for loaded scenes. This structure was suggested by some tutorials and I think it will be good for scalability, but I don’t understand the details. I want to use a script called DisplayManager to handle the loading and unloading of scenes within this framework. The problem is this: any script attached to the root node (“DisplayInsignio”) is not an autoload, so it won’t be accessible by other scripts, such as my DataManager, which needs to call functions to load and unload scenes. On the other hand, if I make DisplayManager into an autoload, it won’t know the location of scenes within the root tree, as it will no longer be attached to the root node.
Now, I am aware that I can probably solve this by using an autoload with hard-coded paths via get_tree() or something. This solution seems dangerous and inelegant though. For example, won’t it break autocompletes? If you think it’s the best/only solution, please tell me the safest way to handle it.
Overall, my question is: what is the most programmatic way to control scene transitions from an autoload, and to access the children of the root scene?
My scene tree looks like this. ManageDisplay is attached to DisplayInsignio. As you can see, Data, devFeed, and MainMenu have scenes attached by default. The “currentChapterSection” will contain the actual meat of the current gameplay mode, whether it’s a VN-style conversation, a crafting menu, or an action-adventure segment. Thus, it needs to be changed dynamically according to lists loaded from file. For example, Chapter 1 might include a conversation, then a battle, then a conversation.
ManageDisplay.gd looks like this:
extends Node3D
@onready var sectionRoot := $currentChapterSection/currentChapterSectionRoot
func getSectionRoot():
return sectionRoot
I want ManageData to have a function like this:
func startSection():
var sectionRoot = ManageDisplay.getSectionRoot()
sectionRoot.add_child( blah blah blah... )
