Can I instance a tscn into addon at edit-time?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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?

thank you all

:bust_in_silhouette: Reply From: Zylann

Given what I see in the doc: EditorPlugin — Godot Engine (3.0) documentation in English

I see that EditorPlugin doesn’t expect a scene as input. You can only define scripts as custom types.

If the editor crashes for doing so instead of telling you the error, I think you should report this issue on Github.

:bust_in_silhouette: Reply From: fiaful

in the end I managed to do it manually, beating and beating my head again, doing so:

  1. I delete the script from the tscn of my node
  2. rename the tscn with a different name
  3. in the script of my node (which will be linked dall’addon), in the function _init, load and instanzio the previously renamed tscn
  4. 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():

in this way it works…