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 pvpoodle · Aug 03, 2013 at 12:59 AM · prefabdestroyinstancechild object

How to destroy a game object within an instance of prefab

hi, i am new to unity and I would like some help with this problem.

i am trying to make a simple maze generator. I have a prefab called "cell" which has 5 cube objects within it to represent the 4 walls and the floor. I am able to instantiate the prefab to form a 10x10 grid, with each instance having a unique name such as cell_1 , cell_2... to track and access them at runtime with gameobject.find();

to generate the maze ,the algorithm im using will choose a random direction and move forward by 1 cell in that direction if certain conditions are met. (the algorithm itself is not relevant to this question)

the problem im having is with destroying the walls between the two cells to form a path for the maze.

i cant seem to be able to find a way to access the individual wall game objects contained within the instance of the cell prefab. (are these considered children of cell game object?)

am i missing something here or is there another way to achieve this?

thanks in advance.

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
Best Answer

Answer by Paulius-Liekis · Aug 03, 2013 at 09:27 PM

Something like this?

 GameObejct cell = gameobject.find("cell_5");
 Transform wall = cell.transform.find("wall_3");
 Destroy(wall.gameObject);
Comment
Add comment · Show 1 · 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 pvpoodle · Aug 04, 2013 at 06:29 AM 0
Share

this is exactly what I was looking for. works perfectly when integrated into my code. so much better than the work around I was trying to implement by triggering a script component on individual walls with a destroy function.

thanks a lot mate.

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

15 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

Related Questions

How to refer to a collision between clones of the same prefab? C# 1 Answer

Problem destroying cloned prefabs 1 Answer

Destroy an instance of a prefab 1 Answer

Instantiated object is destroyed in scene, but still logs as existing in console. 1 Answer

Destroying an instantiated prefab particle effect 4 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