• 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 Fingerlights · May 13, 2016 at 08:35 PM · prefab-instance

Deleting Children of Prefab

Hey! in my game, I have "Room" prefabs, that basically are reusable areas, that are randomly re-instantiated as a new "Room" every time the player finishes a "Room" (think, infinite runner?) - While, in that room, some objects in it get deleted.

When the room is re-created, it is instantiated without the objects, that were deleted (in scene). Is there a way to only delete the objects, from the currently created room, that does not affect the prefab of it?

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

Answer by FortisVenaliter · May 13, 2016 at 08:42 PM

It shouldn't happen that way... Are you sure you're actually deleting the objects in the scene and not the objects in the prefab? The prefab should never be affected by the behaviour of instances in the scene.

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 Fingerlights · May 13, 2016 at 09:04 PM 0
Share

Hey! that's what I thought... and thanks for the swift reply -

So (note this is very bad code, this is my second ever game, my first, not being very big...) this is a small sample of the code that is being called, that is deleting the object.

 void OnTriggerEnter(Collider other)
     {
         if (other.gameObject.CompareTag("StartRight"))           
         {
             rRig.Send$$anonymous$$essage("Set$$anonymous$$oveNowTrue");
             Destroy(gameObject);
         }
 
         if (other.gameObject.CompareTag("StartFloor"))
         {
             manager.Send$$anonymous$$essage("StartFloor");
             Destroy(gameObject);
         }


But when I re-instantiate the room (with this code, (note: currently there is only one room, but using random range to randomize which room it spawns)

 roomSelect =  Random.Range(0, 0); // change max number
             if ( roomSelect == 0 ) 
                 {
                 Instantiate(roomZero, roomArea.transform.position, roomArea.transform.rotation);
                 }


The objects I've deleted, and only those objects, are definitely missing.

TBH, I didn't even realize it was possible to affect the prefab, without changing it in the inspector (again I am very new to this) ...

Any help would be $$anonymous$$assively appreciated!

P.S Sorry for the sloppy code.

avatar image FortisVenaliter Fingerlights · May 13, 2016 at 09:51 PM 0
Share

Are you sure roomZero is always referring to the Prefab, and not the instantiated scene?

avatar image Fingerlights FortisVenaliter · May 13, 2016 at 10:01 PM 0
Share

Just went and double checked / reconnected it. it's definitely connected to the Prefab.

I think I might have isolated the problem ( I haven't tested it out, because I'm not entirely sure how to) but if the item in scene, is there from the beginning and isn't a (clone) would affecting it, affect the prefab? if so - how would I alter it, so it can exist on load, while not needing having it be "connected", would I have to instantiate it @ load time, or is there a way to do this (changing the objects name?) ? --- sorry if I'm being confusing =D and thanks.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

54 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

Related Questions

How to AddListener() (from code) featuring an argument for multiple buttons? 0 Answers

How to set instantiated game object as child on collision in C# 0 Answers

Imported object is transparent where it shouldn't be. 0 Answers

Storing array of game objects in editor mode and click play corrupt the array.,Can't get game object from array after click on the start. 0 Answers

Array or List, Index out of range, I've tried everything.. any other way of passing a list of values of an instantiated prefab to another script 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