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 /
avatar image
0
Question by EscapeGoat · Jul 31, 2016 at 12:19 PM · destroygetcomponentfindprefab-instance

Delete a specific instantiated prefab by its vector3 coordinates?

Hi,

I have a Vector3 array (gameBlocks), ten by ten by ten, with each vector3 holding the coordinates for an instance of my prefab GameBlock. The array is storing the individual coordinates, in a sort of grid, but I have also instantiated the GameBlock prefab to each of those coordinates, creating a large block made of 1000 smaller blocks. Maybe I don't need to do both, but I'm between noob and intermediate levels with scripting, and am having trouble understanding how to handle instantiated objects, most specifically deleting an instantiated object, as I don't know well enough how to get the object back and manipulate it. I can delete an object with a mouse click, but struggle to do it entirely in code.

I am at the point now where I want to find all of the GameBlock items that are live in the scene, and that match with my list of vector3 coordinates in a list called ClearBlocks, then to delete each of them from the scene and from the list. Here is the code, below, and note that I have commented out the one line that I just can't seem to get right. This function is in my GameBlock script, which is attached to the GameBlock prefab. The GameBlock prefabs are instantiated by the Chunk class, which holds the gameBlocks array.

I can post more of my code if you need it, but I suspect you won't; let me know, and I'll be happy to do so.

Thanks!

void ClearAdjacents(){

     foreach(Vector3 block in ClearBlocks){
         
         for (int x = 0; x < 10; x++) {

             for (int y = 0; y < 10; y++) {

                 for(int z = 0; z < 10; z++) {

                     Vector3 tempVector = new Vector3(x,y,z);
                                                                                 
                     if (Chunk.gameBlocks[(int)tempVector.x, (int)tempVector.y, (int)tempVector.z] == block){
                         //GameObject.Destroy(GameBlock(x,y,z));    <---????
                         ClearBlocks.Remove(tempVector);
                         count --;
                         Debug.Log(transVector + "added to ClearBlocks list.");
                         Debug.Log("List count = " + count);
                     }
                 }
             }
         }
     }    
 }
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 EscapeGoat · Aug 03, 2016 at 05:57 PM 0
Share

What do I have to do to get someone to respond to this?

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Access a GameObject through it's tag, using a string. 1 Answer

Limiting respawns on scene 1 Answer

GetComponent: Easy help 1 Answer

Destroy(GetComponent(...)) not working 1 Answer

How do I get the Player's Health Script as Component? 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