Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by NPS · Mar 16, 2013 at 02:42 PM · gameobjectinstantiateduplicatecopy

How to duplicate a GameObject?

This is not a duplicate! Why? Because I've tried different variants of Instantiate() with gameObjectToCopy and its transform as parameteres and none did the trick. What I want is exactly the same object (the same size, position, rotation, material, everything) but, of course, a copy, not a reference. But when I use Instantiate() the result is weird - the cloned object is scaled down/missing its material/whatever. So how to duplicate a GameObject to get the exact copy (in script)?

Example code:

 copy = ((Transform)Instantiate(piece.transform, piece.transform.position, piece.transform.rotation)).gameObject;
 copy = (GameObject)GameObject.Instantiate(piece);
Comment
Add comment · Show 10
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image whebert · Mar 16, 2013 at 02:45 PM 0
Share

Can you show some code of one of your attempts? I've used Instantiate and it seems to work fine.

avatar image robertbu · Mar 16, 2013 at 03:21 PM 0
Share

Instantiate() is the right way. Is this a prefab? Are you making material/scale changes in scripts? Are you using a "real" prefab or are you using a scene object? As @whebert asks, can you show us some code?

avatar image NPS · Mar 16, 2013 at 04:13 PM 0
Share

@wyckhebert @robertbu It's an object (not a prefab) and I'm making some material/scale changes to it in script (before trying to duplicate). Example code added in question.

avatar image robertbu · Mar 16, 2013 at 04:25 PM 0
Share

I've never had this trouble with a "normal" game object. Instantiate() always produces a perfect copy. I've read some posts where people have had scale issues with object containing animations. Can you duplicate this issue using the same material changes on built-in primitives? What material changes are you making?

avatar image robertbu · Mar 16, 2013 at 06:22 PM 1
Share

Everything that has the same material at the start of your app will share that material. Any material change at runtime will result in that shared material being duplicated and the object getting its own unique material instance. This includes shader changes. This doesn't explain why you are having problems with Instantiate(), but just wanted to point out that even a small change may have a large impact on your object's environment.

I've never had this problem, and I did some searches and came up empty for other people having this problem. So whatever it is, it is likely rare (and may not be an Instantiate() issue at all). Could it be a mesh issue? That is, if you replace the mesh you use without another authored in a different environment does the problem still occur? Are you making the object a child of another object?

Without more information or a cut down version of the project to play with (or someone who has had this specific problem reading your question), all the list can give you is guesses.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
-2

Answer by TheCreeperMiner · Mar 29, 2015 at 06:28 PM

g00d Try to select object and then click CTRL + D... :D

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
-3

Answer by CyberBlack · Mar 16, 2013 at 02:46 PM

Try to select object and then click CTRL + D...

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NPS · Mar 16, 2013 at 04:11 PM 1
Share

Sorry for not being specific - I need to do this in script.

avatar image CyberBlack · Mar 16, 2013 at 05:30 PM 0
Share

Oh, okay, i thought you need an example :D

avatar image TheCreeperMiner · Mar 29, 2015 at 06:20 PM 0
Share

I liked Try to select object and then click CTRL + D... Because I'm not good in scripting, better I'm begginer in unity

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to call a method when a GameObject has been duplicated? 4 Answers

Instantiate problem 1 Answer

OnParticleCollision registering twice? 1 Answer

Problem in Instantiate Gameobject Through Network 0 Answers

Finding multiple objects by the same tag as to place them in one array? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges