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 Jeff Ciaccio · Jun 29, 2010 at 04:41 PM · instantiatedestroy

how to destroy an object then instantiate another from a prefab

I've got an object called board_new that was made from a prefab with the same name. I want to destroy the current instance and then instantiate another at a new location. Can somebody tell me how this is done? There will only be one board_new instance at any given time.

Thanks

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
1

Answer by Mike 3 · Jun 29, 2010 at 04:43 PM

Destroy(instance);
instance = Instantiate(prefab, newPos, newRot);
Comment
Add comment · Show 8 · 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 Jeff Ciaccio · Jun 29, 2010 at 04:48 PM 0
Share

so do I need to attach this script to the prefab?? Right now i've got it on a controller object that simply creates and destroys other objects (and keeps score, etc).

avatar image Mike 3 · Jun 29, 2010 at 05:02 PM 0
Share

no, anywhere you like - as long as it keeps a reference to the prefab and the instantiated object

avatar image Jeff Ciaccio · Jun 29, 2010 at 05:06 PM 0
Share

So within my script attached to the controller, I've got

         var board_new = GameObject.Find("board_new");
         Destroy (board_new);
         var randDist: float; //distance for the new board
         randDist = Random.Range(9.0, 12.0)/3.2808398950131234 ; //this is 9 - 12 feet converted to meters
         Instantiate (board_new, Vector3(randDist, .156, 0), Quaternion(0,270,0));
avatar image Mike 3 · Jun 29, 2010 at 05:11 PM 0
Share

Need to swap it around a bit - you destroyed the object you're trying to instantiate. move the destroy after the instantiate, and it'll work fine

avatar image Jeff Ciaccio · Jun 29, 2010 at 05:13 PM 0
Share

But how will it know which one to destroy since I will have two instances?

Show more comments

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

1 Person is following this question.

avatar image

Related Questions

Guided Missiles help? 2 Answers

How can I destroy objects and instantiates new in Array? 2 Answers

Destroy and instantiate the game objects using keyboard event 1 Answer

how to destroy camera instatiated from prefab? 0 Answers

Could someone show me examples of how to use void OnDestroy() to instantiate an object? 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