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
0
Question by kishsolanki · Jun 26, 2015 at 11:11 AM · gameobjectinstantiateclone

instantiated gameobjects(clone) don't have components of its original gameobject.

Hey guys... I have 10 same objects in scene. I have a script that is attached to all those objects and some of the code of that script is as follows:

     Destroy (gameObject);
     Object.Instantiate (gameObject, position, Quaternion.identity);

after destroying those 10 gameobjects, I instantite those objects at same time as shown in code. but, the problem is that when I instantiate those gameobjects, they have disabled components of destroyed gameobjects like script, audio source etc. I got a solution that shows that if i first instantiate object and then destroy the original ones, then this problem is solved. But its not suitable solution for me because if i first instantiate and then destroy originals, then the new instantiated objects wont stay on floor, they fall, as I have tried it. So I want a solution of it that gives ENABLED COMPONENTS of new instantiated gameobjects. pls help if any one have a solution.

Comment
Add comment · Show 1
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 superbsumit · Jun 29, 2015 at 06:10 AM 0
Share

Why can't you just Enable/Disable a gameObject ins$$anonymous$$d of Instantiating/Destroying?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Cherno · Jun 26, 2015 at 11:46 AM

Instantiating first and then Destroying is the way to go. If the new gameObjects fall, that's a problem with their physics, not with the way they are instantiated. It would help to know if the objects have rigidbodies and colliders and how these are set up.

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 kishsolanki · Jun 26, 2015 at 02:18 PM 0
Share

yes. objects have rigidibodies, so sometimes they fall and sometime stands on floor. i dont know what to do. now i destroy first and then instantiate as shown below:

 Destroy (gameObject);
 Object.Instantiate (gameObject, position, Quaternion.identity);

and when i instantiate those objects simultaneously as mentioned, the game in play mode chock ups for 1-2 seconds at the time of the instantiation.

and for getting the components, I use the following code:

 GameObject GO = Instantiate (gameObject, position, Quaternion.identity) as GameObject;
         GO.GetComponent<Script> ().enabled=true;
         GO.GetComponent<AudioSource> ().enabled = true;
avatar image Cherno · Jun 26, 2015 at 02:28 PM 0
Share

Ok, so you are making a copy of the very gameobject this script is attached too. I suspect that the rigidbodies of both objects collider upon instantiation. Try setting the original go's rigidbody to Is$$anonymous$$inematic = true, then instantiate the copy, then set the copy's rigidbody to Is$$anonymous$$inematic = false, and then destroy the original gameobject.

avatar image kishsolanki · Jun 29, 2015 at 05:54 AM 0
Share

i cant keep original gameobject's Is$$anonymous$$inetic=true because if I keep that, then they wont collide and I want them to collide and behave as a physic dynamic component, not as static. BTW now script is running fine but the only problem is that when I instantiate objects, game/camera chokes up for 1-2 seconds. 10 objects instantiating simultaneously is the problem I think. But that is what I needed. Don't know how to stop being choke up the game !

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Instantiated Object's Scripts not enabled? Not sure why 3 Answers

Adjusting Rotation of Instantiated Objects 0 Answers

Trying to Clone 1 of 5 GameObjects in a array 1 Answer

Instantiating a GameObject from scene that changes 1 Answer

How can I destroy an specific clone already instantiated, when there's more than one? 1 Answer


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