Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addon (plugin) nodes cannot have custom scripts or receive signals #2420

Closed
tavurth opened this issue Mar 7, 2021 · 7 comments
Closed

Addon (plugin) nodes cannot have custom scripts or receive signals #2420

tavurth opened this issue Mar 7, 2021 · 7 comments

Comments

@tavurth
Copy link

tavurth commented Mar 7, 2021

Describe the project you are working on

I would like to make some of my more common utilities into addons (plugin), so they can be reused across different projects.

Describe the problem or limitation you are having in your project

When instancing a node from a plugin, that node cannot accept a new custom script (as the plugin itself is a script)
The instanced plugin cannot receive any signals from other nodes either, which makes it very hard to make them useful.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

I would like to be able to use .tscn files as the root of the plugin.
add_custom_type would support .tscn files instead of only .script files

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Pretty much as above, add_custom_type would support .tscn

If this enhancement will not be used often, can it be worked around with a few lines of script?

I've not found a workaround for this

Is there a reason why this should be core and not an add-on in the asset library?

It's part of the editor plugin system

Related

@tavurth tavurth changed the title Addon (plugin) nodes cannot receive signals Addon (plugin) nodes cannot have custom scripts Mar 7, 2021
@tavurth tavurth changed the title Addon (plugin) nodes cannot have custom scripts Addon (plugin) nodes cannot have custom scripts or receive signals Mar 7, 2021
@YuriSizov
Copy link
Contributor

YuriSizov commented Mar 7, 2021

I don't understand the issue whatsoever. First of all, it talks at the same time about instancing nodes within a plugin and about declaring custom types from a plugin, which are two different things. But in both cases you can use signals and whatnot.

It seems to me you miss something in understanding how plugins work, not that there is an issue or a missing feature in the engine. Please describe your problem/limitation in more detail.

@tavurth
Copy link
Author

tavurth commented Mar 7, 2021

Yep perhaps you are correct!

Screenshot 2021-03-07 at 17 15 50

Here's an example of one of my plugin nodes.
As you can see the script section is greyed out. I cannot add a new script there.

Screenshot 2021-03-07 at 17 16 27

Note that when I try to add an incoming signal to that custom node, it is inaccessible in the tree (meaning I can't add the signal there)

Here's the code used to generate that editor plugin:

tool
extends EditorPlugin

func _enter_tree():
	add_custom_type("cs-Data Source", "MarginContainer", preload("data.gd"), preload("icon.png"))

func _exit_tree():
	remove_custom_type("cs-Data Source")

Am I doing something wrong there?

@YuriSizov
Copy link
Contributor

As you can see the script section is greyed out. I cannot add a new script there.

Indeed, there is such a limitation. The problem is that custom nodes are not treated the same as built-in nodes, which means that, basically, this node already has a script, and you cannot override it. There are several proposals linked to this problem but everything more or less comes to #22 and a better type system for custom type.

As a workaround you can, for example, set up an exported property for a custom script. It can be a script extending Object with its instance just stored on your custom node, or it be a script extending Node and you can create it as a child node on the tree. Either way, you'd talk to it from your custom type script. It's not as flexible, but it will work in the meantime.

Note that when I try to add an incoming signal to that custom node, it is inaccessible in the tree (meaning I can't add the signal there)

I don't connect signals from the UI, so I'm not sure why it looks like that and what can be a limitation. It shouldn't, IMO, be grayed out and unaccessible.

@SIsilicon
Copy link

If i remember correctly, you can still at least extend from the custom script. That's what I do when I want to add code to a plugin node.

@tavurth
Copy link
Author

tavurth commented Mar 7, 2021

As a workaround you can, for example, set up an exported property for a custom script. It can be a script extending Object with its instance just stored on your custom node, or it be a script extending Node and you can create it as a child node on the tree. Either way, you'd talk to it from your custom type script. It's not as flexible, but it will work in the meantime.

Screenshot 2021-03-07 at 22 52 16

Yep I'm already following this pattern as seen in the screenshot above.

The problem with Signals still exists however, as I cannot send signals to that child script (or child node)

If i remember correctly, you can still at least extend from the custom script.

I can extend from a custom script in my Addons folder, but that means I lose the nice features of the EditorPlugin, and the node does not have the custom icon etc.

@tavurth
Copy link
Author

tavurth commented Mar 7, 2021

Seems like this signal thing is closer to a bug report if that should be working

@tavurth
Copy link
Author

tavurth commented Mar 7, 2021

Current workaround for signals seems to be just double clicking on the addon node, it does not show as clickable but works when you double click.

I've marked this as a bug here: godotengine/godot#46772
I'll close this issue, as the other parts are present in the other issue mentioned above.

Thanks guys!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants