Replies: 4 comments
-
I think we could have the annotation set a property usage bit flag (which we could also set by other means), and then |
Beta Was this translation helpful? Give feedback.
-
Without an annotation this isn't something that should be done IMO, emitting this on any property change isn't desirable or recommend, but an annotation does make sense However having the signal emit without there being any behaviour change in the resource doesn't necessarily make sense, I'd say the signal should be emitted not when a property changes as such, but when the resource itself is modified in some deeper way, i.e. changes how it's rendered or behaves, and this usually involves having it act when the property is set I'd say the signal communicates that the resource has updated its total state and should be responded to, when for example a dynamic texture recreates its internal state, i.e. it doesn't reflect the way others can respond by reading its properties, but by reading the data and behaviour those properties control |
Beta Was this translation helpful? Give feedback.
-
I think this is one of those issues that could be solved by reusable setters/getters (godotengine/godot#78991), custom annotations or something else. We have many related proposals such as This is especially true for syntactic sugar and other shorthands. I think that a good shorthand is characterized by simplicity and lack of alternatives. It does exactly one thing that must be clear and cannot be done any other way. There is either no room for customization at all, or the parameter(s) are obvious and the behavior itself is still straightforward. If each of your properties is unique enough, then I think the boilerplate is ok, there shouldn't be too many properties for this to be a big problem. If you have a lot of homogeneous properties, then you can use different approaches to reduce the boilerplate:
|
Beta Was this translation helpful? Give feedback.
-
Interesting. Thank you @AThousandShips for helping me better understand the thinking behind the Also, I very much agree with your sentiment @dalexeev about providing facilities to solve a wider range of problems. I love the idea of being able to create custom annotations, so I'll keep an eye on that instead. 🙏 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
From the Resource class docs:
When creating a class that extends
Resource
, if you want to emit thechanged
signal any time the value of a custom property is changed, you need to implement a custom setter for that property, like this:Doing this for more than a couple of properties can add a lot of unnecessary boilerplate to your custom resources. It would be avoided entirely if calling
emit_changed()
were the default behavior for resource properties.Possible Implementation: Modify core/io/resource.cpp to override the
_set
method:Alternatively, to avoid any compatibility issues, a new
@emit_changed
annotation could be added to GDScript:Possible Implementation: This would require an additional change to add modules/gdscript/gdscript_parser.cpp, to add the annotation, but otherwise I imagine the change to core/io/resource.cpp would look something like this:
Curious to hear what you all think. If enough folks like the idea, I'd be happy to take a crack at contributing a PR.
Beta Was this translation helpful? Give feedback.
All reactions