I want to create a duplicate object that has been altered through gameplay with matching attributes. I could instantiate a new object from the prefab and then update all the attributes but I was wondering if I could just duplicate the existing object?
Thanks.
Instantiate is just a fancy/smart copy, and works perfectly fine on existing gameObjects. In fact, I’ve seen many people spawn existing objects before they learned prefabs (every Instantiate is from a single pre-made gameObject stuck at (999,0,0).)
To explain: gameObjects technically have links to their components. A simple copy wouldn’t know it had to also copy all the components. Likewise, it wouldn’t know it also had to copy any child gameObjects. Instantiate is smart enough to know the stuff you want copied, and what you don’t (like, don’t copy Mesh assets.) As best I know, a prefab is really a regular gameObject, just not in the scene (so never Updated, collided, rendered,) waiting to see if you ever want to copy it.
NOTE: the reason people say to never Instantiate an existing object isn’t because it doesn’t work. It’s because copying changes is almost never what you want to do.