Much like how the get_name() and get_owner() method of Node was deprecated in favor of the name and owner property, why not do the same for a parent property (or in addition to get_parent())?
To be exposed as a property it needs to have both a setter and a getter, while parent has no set_parent. If parent were exposed as a property, people should be able to do parent = some_other_node, which is far from trivial (see #23816).
SceneTree.root has no setter but is a property. (or is this the cause of #24429 ?)
Can't a property have no setter?
Not sure how this works with GDScript but properties in ClassDB's classes can be read only.
Iirc, GDscript can also have read only properties by using a lone _ before a comma. Much like my existing pr, it's debatable how important it is when you can simply type $...
I think both my pr and this issue would be better addressed with a proper ExtensionMethod system. (Or something lile it.)
Seems like I forgot converting get_parent to parent in my PR.
Note that setting parent might be allowed, and would eliminate a lot of this boilerplate:
# Old
if thing.is_inside_tree(): thing.get_parent().remove_child(thing)
if new_parent: new_parent.add_child(thing)
# New
thing.parent = new_parent
Setting a parent property is even the main way to go in Unity, so a setter would be possible. It obviously does not allow options, but we are not deprecating add_child or possible reparent_node functions, right? The setter would just use the most common approach with default behavior.
I don't mind if there is no setter, though.
This proposal was rejected as per https://github.com/godotengine/godot/pull/36301#issuecomment-587026596.
The related proposal to add a method to reparent while keeping the transform for transform-enabled nodes is fine though: #21781.
Most helpful comment
Seems like I forgot converting
get_parenttoparentin my PR.Note that setting
parentmight be allowed, and would eliminate a lot of this boilerplate: