When creating a node defined from a script, base node properties set in _init() are not treated the same as user defined properties. #12062
DragonBoyXVI
started this conversation in
General Discussions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When create a new node using a script, say an Area2D component, it makes sense to set variables to a default value in the _init() callback, and define new default values with the _property_can/get_revert() functions.
This works flawlessly with properties exposed with @/export or _get_property_list(), however it doesn't with base node properties.
For example, the Area2D's collision_layer value, the property is set to the value saved in the file before _init() is run, so collision_layer is always the value defined in _init().
So now, whenever a AreaComponent is added using the + button, collision_layer is always be the _COLLISION_LAYER_DEFAULT value when the scene is loaded.
Also note that scenes created using the "Instantiate New Scene" button do not suffer these issues, however I think this adds another layer of confusion to the issue. It makes creating components have the unnecessary step of adding a scene, where you have to remember the file name instead of the class name.
I'm sure the reason for this is how properties are handled internally in Godot with pure script nodes, as opposed to scenes, but I am not knowledgeable in Godots innards, let alone C++, hence the discussion. Any thoughts, or insight?
Beta Was this translation helpful? Give feedback.
All reactions