godot-rust / gdext

Rust bindings for Godot 4
https://mastodon.gamedev.place/@GodotRust
Mozilla Public License 2.0
2.73k stars 167 forks source link

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

Open jrockett6 opened 3 months ago

jrockett6 commented 3 months ago

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 commented 3 months ago

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.

Bromeon commented 3 months ago

What exactly needs changing in gdext?

jrockett6 commented 3 months ago

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]?

lilizoey commented 3 months ago

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