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

Setting exported node properties from the inspector bypasses their setter #74050

Closed
theraot opened this issue Feb 27, 2023 · 7 comments · Fixed by #76389
Closed

Setting exported node properties from the inspector bypasses their setter #74050

theraot opened this issue Feb 27, 2023 · 7 comments · Fixed by #76389

Comments

@theraot
Copy link
Contributor

theraot commented Feb 27, 2023

Godot version

v4.0.alpha11.official [afdae67] (when the feature was added) and newer (still happens in RC6)

System information

Windows 10

Issue description

I'm unable to handle when the user sets an exported node property (this feature: #62185) from a setter in the editor (tool script).

I don't know if this is intentional or not, but for me it was unexpected. I had to revert back to NodePaths.

Steps to reproduce

  • Create a scene
  • Attach a script to a node
  • Add @tool at the top of the script
  • Export a node property with a setter, preferably with an easy way to see if it executed:
     @export var node:Node:
     	set (mod_value):
     		prints("node", mod_value)
     		node = mod_value
    
  • Save, close and open again the scene to make sure the tool script is running in the editor
  • Set the node property from the inspector
  • Observe that the setter didn't run

The setter is not bypassed when running the game, it is only bypassed in the editor.

We can compare with a NodePath property, which setter is not bypassed regardless if it is in the editor or in game runtime.

Minimal reproduction project

nodepath.zip

@lyuma
Copy link
Contributor

lyuma commented Feb 28, 2023

It definitely works, but I had some issues getting it to run at first.

Can you try saving / closing and opening the scene and see if that makes the script work?

I just did this myself a few hours ago, and I noticed my GDScript code wasn't getting updated when I made changes. Closing and opening the scene seemed to make the setter work for me.

@theraot
Copy link
Contributor Author

theraot commented Feb 28, 2023

Nope. I cannot get the setter of the node export to work. Addendum: on the editor I cannot get it to work, on runtime it works.

@lyuma
Copy link
Contributor

lyuma commented Feb 28, 2023

Ah, I missed that there was both a Node and a NodePath. Only the NodePath export works.

I can confirm the @export var node: Node does not seem to invoke the getter/setter while in the editor.

Set metadata/_editor_prop_ptr_node
Set metadata/_editor_prop_ptr_node
set node path
node_path 
Set node_path
set node path

it seems that somehow it uses metadata/_editor_prop_ptr_node instead of node for the node variable. If there was a custom _set, perhaps it can possibly detect changes to that property, but it would be a hack.

@michaelhue
Copy link

Adding to this: the value of a @export var node: Node property will always be null inside the editor (i.e. for @tool scripts), even when a node is selected.

@Tuckertcs
Copy link

This issue has the topic:gdscript label, but it exists in C# as well (see #74141, #76182, or #76190).

I'll also add that the above comment says the inspector will always show null, however I've found that the inspector always shows what you drag into the property, regardless of the actual property's value (i.e. drag a node in, set to null in code, still see node in inspector).

@theraot
Copy link
Contributor Author

theraot commented Apr 18, 2023

@Tuckertcs The inspector will show the Node correctly. What @michaelhue was saying is that if you try to get the value from a tool script (a script running in the editor) it will get null.

@krazyjakee
Copy link

krazyjakee commented May 12, 2023

The example given here: https://docs.godotengine.org/en/stable/classes/class_object.html#class-object-method-get-property-list works but when holding_hammer is of type Node, the setter logic actually never runs therefore making the use case impossible.

akien-mga pushed a commit to akien-mga/godot that referenced this issue May 31, 2023
Fixes to changes from godotengine#76114.

This PR remove the hack with pointer and replace it with a proper handling
from EditorPropertyNodePath of both NodePath and Node. Also needed to revise
a bit the saving and loading of scene to handle properly the change.

Fixes godotengine#74050.
Fixes godotengine#74141.
Fixes godotengine#75981.
Fixes godotengine#76642.

Revert "Fix typed array export... again"

This reverts commit da8d673.

Co-Authored-By: Tomek <[email protected]>
@akien-mga akien-mga added this to the 4.1 milestone May 31, 2023
krazyjakee added a commit to NodotProject/nodot that referenced this issue Jun 1, 2023
krazyjakee added a commit to NodotProject/nodot that referenced this issue Jun 15, 2023
* various tweaks and changes

* more independant swimming logic

* signal connector fix using godot 4.1 dev 4

godotengine/godot#74050

* character mover tweaks

* fix signal connector again

* add a fixed camera area

* various fixes

* bug fix for global signal and collectableinventory item add
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants