Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Valkarth · Jun 10, 2017 at 04:05 AM · instantiatecolliderdestroycomponentclone

Cannot destroy the SphereCollider on Instantiated Objects

Hey,

I currently have made a script which instantiates 20 objects (stars). The issue is that I want to destroy then add a SphereCollider on each other objects but I can't got it to work. My function below:

public void SpawnStars() { //Debug.Log("The Size of the Array is " + SpawnPoints.Length); Vector3 randomPosition;

     while (starscloned == false) 
     {
         randomPosition = new Vector3(Random.Range(-400f, 400f), Random.Range(100f, 400f), Random.Range(-400f, 400f));
         //The Vector called randomPosition is randomly assigned X, Y and Z co-ordinates by the "Random.Range" function.
         // The generated Y co-ordinate must be between 0 and some number because a star can never be below the horizon.
         //https://forum.unity3d.com/threads/randomly-generate-objects-inside-of-a-box.95088/

         randomPosition = transform.TransformPoint(randomPosition * 2.5f);
         // The randomPosition is maximised and scaled appropriate to the scene.

         newClone = Instantiate (stars, randomPosition, SpawnPoints [spawnIndex].rotation);
          //Instantiate generates a clone of an object. The function is divided into 3 components;
          //Object, Position, Roation
          //The object is the model which is being cloned
          //The Position is the position where the object will be spawned
          //Quaternion is the rotation component of the new spawn


         newClone.name = ("StarClone" + spawnIndex);
     
         sphereCollider = newClone.GetComponent<SphereCollider>();
         sphereCollider.enabled = false;
         Destroy(sphereCollider);

         //newClone.AddComponent<SphereCollider> ();
         //newClone.GetComponent<SphereCollider> ().enabled = true;
         //newClone.GetComponent<SphereCollider> ().center = Vector3.zero;
         //newClone.GetComponent<SphereCollider> ().radius = 1f;

         // The new Object is intrinsictly named for future use

         spawnIndex = spawnIndex + 1;
         //Essentially a counter in itself

         if (spawnIndex == SpawnPoints.Length) {
             starscloned = true;
         } else {
             //other.Classify ();
         }
     }
     //Debug.Log ("The clones have been created and the loop has been exited.");
 }


Any idea's would be appreciated. Thanks heaps!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by cclar202 · Dec 03, 2019 at 03:32 PM

I've successfully done this just with:

Destroy(gameObject.GetComponent());

Not sure why yours isn't working. Though you don't need to disable the collider on line 22, if you're just going to destroy it.,I've successfully done this just with:

Destroy(gameObject.GetComponent());

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

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

Related Questions

destroy asset is not permitted to avoid data loss? 0 Answers

I need help destroying a clone on function. 1 Answer

Bullet clones will not be destroyed. 2 Answers

Destroy the first instantiated clone after 4 have been instantiated 1 Answer

How to destroy a cloned/instantiated enemy from script? 0 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