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 brittaschulte · Jun 18, 2018 at 01:05 PM · prefabsprefab-instance

Breakable objects are still broken after level reset

So my setup is: I have some large glass displays. The player can break them by punching them. I do this like this:

 private void OnCollisionEnter(Collision collision)
         {
             if (collision.gameObject.CompareTag("Player"))
             {
                 if (hasText)
                 {
                     text.SetActive(false);
                 }
                 this.GetComponent<MeshRenderer>().enabled = false;
                 this.GetComponent<BoxCollider>().enabled = false;
                 shatters.SetActive(true);
             }
         }

Now, in the next level I want the displays to be there again, and I want them to be breakable again. So I built a Reset function:

 public void Reset()
         {
             Destroy(shatters);
             shatters = Instantiate(shattersprefab);
             
             if (hasText)
             {
                 text.SetActive(true);
             }
             this.GetComponent<MeshRenderer>().enabled = true;
             this.GetComponent<BoxCollider>().enabled = true;
         }

Which works well enough in making the displays visible again, but when they are punched by the player the shards are already on the groundl, just as they were left in the previous level. It seems as if I'm just re-instantiating the already fallen shards. But I have no clue how this could have happened.

I've been having similar problems throughout this whole project and by now I think I might just be fundamentally misunderstanding prefabs.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by nomadic · Jun 18, 2018 at 08:39 PM

What type of reference is 'shatters'? Is is a GameObject or a script component? My guess is you may be destroying a component without destroying the entire GameObject.

Comment
Add comment · Show 2 · 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 brittaschulte · Jun 20, 2018 at 09:08 AM 0
Share

It's a child GameObject of the display GameObject

avatar image nomadic brittaschulte · Jun 21, 2018 at 10:07 PM 0
Share

If that's the case then my guess is wrong. It is hard to tell much more without seeing your scene and GameObjects. It sounds like you are cloning from the clone ins$$anonymous$$d of from the prefab.

avatar image
0

Answer by Q-Ted · Jun 22, 2018 at 01:32 AM

What is the default active state of the shattersPrefab?

It looks like it is active by default, either changing the prefab's active state to false or setting the instantiated object active state to false should work:

shatters.SetActive(false);

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

89 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

Related Questions

Find Source of Prefab Instance in Editor? 1 Answer

A Question about applying changes to nested prefabs 0 Answers

Newly spawned objects not behaving similar to the original ones.,Newly spawned objects don't behave like the original ones. What do I do? 0 Answers

How do I reference any instance of a prefab? 1 Answer

Instantiating Mesh Error - Mesh has Instance added? 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