+3 votes

I would like to write a plugin for Godot, which adds a new type.

I already wrote this type in a scene called LivePlot.tscn. It is a simple scene with multiple subnodes and a script LivePlot.gd attached to the root node. I then looked into how to write plugins. I followed the official tutorial for a plugin which adds a custom node (this seemed to be very similar to what I want).

My settup in res://addons/LivePlot/ is now as follows:

  • a plugin.cfg with the line script="add_LivePlot_as_a_new_type.gd" in it.
  • the add_LivePlot_as_a_new_type.gd script which effectifly is these 6 lines:

    tool
    extends EditorPlugin
    
    func _enter_tree():
        add_custom_type("LivePlot", "Node2D", preload("LivePlot.gd"), preload("icon.svg"))
    
    func _exit_tree():
        remove_custom_type("LivePlot")
    
  • the icon.svg

  • the LivePlot.tscn and LivePlot.gd. The later has a function _enter_tree(): pass which does nothing, but without it nothing seems to work at all.

After enabling the plugin I can now add a new node, but it is just a node which doesn't have the scene LivePlot.tscn attached to it, only the script. This is not suprising, I never told the plugin about the scene file. But how can I do that?

The official tutorial doesn't mention how to add a scene. I also don't want the user to have access to the internal script LivePlot.gd (the user shouldn't have to bother with that, if they want they can check the source).

How can I add a custom scene as a new type in a plugin?

in Engine by (49 points)

I am trying to create the same things like you :)

Did you find a solution?

I am also trying to do the same thing. Do either of you find out how to do it?

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.