I know I can right-click and duplicate a group, but how do I do that with code? Can I also duplicate with controller overrides with code? I need to do it via code, please help.
The Z.Group node provides a few different functions. They can all be found here: https://docs.zap.works/studio/scripting/reference/group/functions/.
I think if you want to duplicate a group and all it’s content, you will need to call the children() function which will return the children of the group as an array of Z.Node objects.You can then store this array and push the objects found within it, into a new group.
I haven’t tried this but in theory it should work. Let me know how you get on, or if you found another workaround?
Except not every node inherits from Z.Node. An image texture inherits from Z.texture, which in turn inherits from Z.Base, and Z.Base does not inherit from Z.Node . In fact, an image texture does not count towards the number of children a group has. Create an empty group and drag an image texture inside it. children().length will return 0. However when you duplicate a group manually the image texture gets duplicated as well. This is being done in another way.
Hm…however, upon further inspection it seems everything that isn’t a node isn’t visible anyway, so it may not matter, not sure.
Also, I want to copy with controller override, because I want the animated properties to be copied as well. Copying the way you suggest does not do that.
This does not work. Pushed nodes are references. Changing the original or the copy changes the other.