gdext icon indicating copy to clipboard operation
gdext copied to clipboard

Dont allow exporting Nodes from Custom Resources (par with gdscript)

Open jrockett6 opened this issue 2 years ago • 4 comments

Par with gdscript per https://github.com/godotengine/godot/pull/82843

It would be nice if this could be allowed for built-in resources. I left a comment here https://github.com/godotengine/godot/issues/80538

jrockett6 avatar Apr 01 '24 04:04 jrockett6

Oh and maybe I should mention that the current behavior is that it allows you to select a node from the scene to use in the exported field like normal, but instead of adding the node to the scene as a node path (which would be nice for built in resources) it creates an a duplicate of that node that ends up being an orphaned object.

jrockett6 avatar Apr 01 '24 06:04 jrockett6

What exactly needs changing in gdext?

Bromeon avatar Apr 01 '24 16:04 Bromeon

Im not sure how it would want to be shown - like as a compile error or a warning or something else when using the #[export] attribute.

The gdscript behavior is that when you try to

extends Resource

@export var x: Node

you are given an error like: Screen Shot 2024-04-01 at 10 16 59 AM

Currently in Rust (or before this was fixed in gdscript) this leads to some unsuspected user bugs when it lets you set nodes in the editor, but then the nodes are duplicated orphaned objects instead of references as expected.

But I am still curious if this behavior should be allowed (but fixed in Godot - to use node paths and not duplicate the node) for built-in resources, which I asked here. In which case the solution for disallowing this in #[export] attribute would probably not be a viable solution, and I think things would have to be fixed on the Godot side because at that point the behavior is dependent on what the .tscn file looks like.

So to answer the question - maybe the solution is to wait until that question is answered, and if the behavior is to remain the same then add some sort of checks to #[export]?

jrockett6 avatar Apr 01 '24 17:04 jrockett6

here's one way we could disallow it that lives entirely in the type system https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=834bb7d13150904d471eef57e73d1b66

lilizoey avatar Apr 01 '24 18:04 lilizoey

I implemented this via runtime validation at startup. Parametrizing Export for this one little check is too heavy.

It would be nice if this could be allowed for built-in resources.

This hasn't been accepted in Godot, so no...

Bromeon avatar Aug 05 '24 16:08 Bromeon

This hasn't been accepted in Godot, so no...

Right, I should have been more clear. I meant "it would be nice if Godot allowed for builtin resources", and then that would need to be considered here

jrockett6 avatar Aug 16 '24 20:08 jrockett6