Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
4
Question by Srimasis · Sep 10, 2013 at 07:47 PM · instantiatedestroyclone

How to delete instantiated GameObject

I have a simple question , how can I delete a cloned or instantiated object after 1 second without deleting the original. The GameObject is just a 3d object with no scripts attached. All I want to do is instantiate an object at certain coordinates when required and destroy it after 1 second. Any help will be appreciated

Comment
Add comment · Show 2
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 clunk47 · Sep 10, 2013 at 08:09 PM 1
Share

If one of the below answers has resolved your concern, please vote up and accept the answer that best addresses your question. Any other questions that may have helped, an upvote would be nice as well.

avatar image vexe · Oct 06, 2013 at 05:43 PM 1
Share

DEAR @Srimasis: Is there anything else related to we could do for you? - If so, please tell us. Else please tick an answer if it helped you solve your problem to keep the board clean and tidy (it's a way of saying THAN$$anonymous$$ YOU for taking the time to answer and help me), if nothing helped you, then we really appreciate FEEDBAC$$anonymous$$.

4 Replies

· Add your reply
  • Sort: 
avatar image
21
Best Answer

Answer by clunk47 · Sep 10, 2013 at 07:53 PM

Here's a c# example. In this example, I define a GameObject where you will assign a prefab or original to in the inspector. Then we'll 'clone' the object, and instantiate a new instance of it, then destroy it after one second.

 using UnityEngine;
 using System.Collections;
 
 public class Example : MonoBehaviour
 {
     public GameObject original;
     
     void Awake()
     {
         GameObject clone = (GameObject)Instantiate (original, transform.position, Quaternion.identity);
         Destroy (clone, 1.0f);
     }
 }

Here's how you could do the same as above, but in Javascript (Unityscript).

 #pragma strict
 
 var original : GameObject;
     
 function Awake()
 {
     var clone = Instantiate (original, transform.position, Quaternion.identity);
     Destroy (clone, 1.0);
 }

Click here for more info on Destroy(object, float time).

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 Srimasis · Sep 11, 2013 at 04:38 AM 2
Share

Thanks brother but I have a doubt, what if I declare the variable clone as an array, I have to make multiple clones.

avatar image clunk47 · Sep 11, 2013 at 04:48 AM 1
Share

You don't just instantiate an array. Say you have a gameObject array with 10 gameObjects. You'd say something like:

 var gameObjectArray : GameObject[];
 
 var clone = Instantiate(gameObjectArray[3], transform.position, Quaternion.identity);

This is how you would for example, grab the 4th object from your array and create a new instance.

avatar image kiranmandrah · May 08, 2020 at 04:09 AM 0
Share

clunk47 used right code. It works. The GameObject clone means the instantiated clone of the original GameObject. And Destroy(clone, 1.0f) means that destroy the clone GameObject after 1 second. Thanks clunk47.

avatar image
5

Answer by FrimaMickD · Sep 10, 2013 at 07:58 PM

 GameObject mMyClone = (GameObject)GameObject.Instantiate(mOriginalObject); //Create the clone of mOriginalObject

 GameObject.Destroy(mMyClone);//Destroy the Clone

 GameObject.DestroyImmediate(mMyClone);//Destroy without waiting for GC (I think?)
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
1

Answer by getyour411 · Sep 10, 2013 at 07:55 PM

var myVar = Instantiate(go, position, rotation);

Destroy(myVar, 1);

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 Srimasis · Sep 10, 2013 at 07:59 PM 0
Share

Thanks brother I got it

avatar image clunk47 · Oct 06, 2013 at 06:48 PM 1
Share

If you "got it", please ACCEPT THE ANSWER that best addresses your question.

avatar image arthurptj · Nov 15, 2015 at 05:48 PM 0
Share

relax @clunk47

avatar image
0

Answer by Bassem_Magdi · Jul 29, 2020 at 02:09 AM

You can simply nested it into a Destroy function and set the second argument with 1 "seconds" . Destroy( Instantiate(Dust, transform.position, transform.rotation), 1);

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

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

21 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Destroy a specific instantiated clone? 2 Answers

How can I destroy my Instance without renaming it? 2 Answers

Why could I delete my clones onlY in the same order of instantiation? 2 Answers

restricting clone number 2 Answers

Deleting a GameObject 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