Add an _dupicate() -> Resource virtual method to resources #9397
Replies: 1 comment
-
I had this issue as well and would like this to be exposed too. The generic However, before we just expose that as-is, there is another problem to explore: Instead of virtual If the resource has a script, and we want properties of the script to be copied using the default behavior, we would have to run If we don't want to go that route and just allow to override But what if you duplicates nodes? They have a Personally, I initially preferred the first solution (splitting object creation from its copy) as I think it would be ideal (and reflects what I've been doing when I needed "duplicate" functionality in my projects, not necessarily Godot), but considering the existing codebase/philosophy and unless I'm missing options to improve the idea, the second solution ends up simpler overall, it is conservative. It puts all burden on the implementors though, so maybe helpers could make the job easier to avoid mistakes. Though I can't comment about nodes... Some examples of custom resource duplicates in core itself: |
Beta Was this translation helpful? Give feedback.
-
Currently, refcounted properties in custom resources (for example, an arrays, which are quite frequent) are always passed by reference to duplicated copies, making duplicate largely useless for custom resources. I'm proposing adding a virtual override that would be called for custom resources, returning the new resource thus created. This would allow implementing any custom behavior needed to duplicate custom resources.
Beta Was this translation helpful? Give feedback.
All reactions