Topic was automatically imported from the old Question2Answer platform.
Asked By
fiaful
Hi there!
I have a big problem…
I have created a series of scenes that I would like to transform into addon … now, these scenes have various nodes inside them … after making the plugin.cfg file, the main script of the addon (the one with the add_custom_type), my nodes (which inherit from Control), I find them in the selection window of the nodes when I go to add them to the project (perfect), but the contents of the tscn associated with the node, is not loaded.
I tried using preload to load the contents of the tscn into a variable and, in the _ready function, to instantiate it and add it to the scene, but when I switch to the 2d display (in edit-time, to set the properties of the object) , the godot editor crashes
I also tried to move the instantiation to the _enter_tree and _init functions but the result is the same
how can I make sure that when I create my node, also the associated scene is loaded in edit-time?
in the end I managed to do it manually, beating and beating my head again, doing so:
I delete the script from the tscn of my node
rename the tscn with a different name
in the script of my node (which will be linked dall’addon), in the function _init, load and instanzio the previously renamed tscn
then I browse all the nodes in the just obtained instance and for each node, duplicate and add the node to myself.
here is an example extracted from my code:
func _init():
if get_child_count() > 0: return
var gamepad_stick_template = load("res://addons/Gamepad/GamepadStickTemplate.tscn").instance()
if gamepad_stick_template.get_child_count() > 0:
for child in gamepad_stick_template.get_children():
add_child(child.duplicate())