- Home /
Any way to copy and paste GameObjects programatically?
It would be a useful feature. it's impossible to copy objects to a prefab without using an Editor Script so you can't copy an object to a prefab without using a menu option.
Perhaps it's possible to make a "copy to prefab/paste from prefab" function in an Editor Script and access it from a Normal Script?
I dont think it's possible to edit the objects in the Selection of hierarchy, which is held in an array somewhere, and i didnt see any selection copy/paste options in reference.
Is there any way to store GameObjects to a kind of memory and paste them into the game elsewhere?
Answer by Muuskii · Sep 22, 2012 at 09:03 PM
You mean like a deep copy? What specifically are you trying to accomplish here?
From Object.Instantiate
This is essentially the same as using duplicate command (cmd-d) in Unity and then moving the object to the given location
Thanks $$anonymous$$uuskii! O$$anonymous$$G i didnt realise! i thought you could just instantiate prefabs, although it may be O$$anonymous$$ to instantiate to copy game objects. ok.
I am making some geometry with central symmetries, and as it's procedural, it's best to make the mesh on the fly and then copy the symmetries, and it also makes the code simpler and easier to control via modular program$$anonymous$$g.
You're welcome. The idea of instantiating non prefabs is an alien idea to me as well. I don't usually use it ever.
If the answer solves your question, please do mark it as correct.
Thank you.
hiya, i vote for the answer, it means i mark it as correct? there is another option?
There should also be a checkmark button underneath where you see the thumbs up and down buttons. Click that to indicate that an answer is correct.
Thank you/
Your answer
Follow this Question
Related Questions
How do I keep a texture different on copied objects? 1 Answer
How to set prefab's script value programatically? 1 Answer
Can a prefab be written in code? 3 Answers
Monster Spawner 3 Answers
Coin collecting with prefabs 2 Answers