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 /
  • Help Room /
This question was closed Dec 09, 2015 at 07:49 PM by Hydropulse17 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Hydropulse17 · Dec 09, 2015 at 07:36 PM · collisioninstantiateprefabs

Two prefabs instantiated instead of one?

I'm making an asteroids clone. When I fire a beam from my ship, it hits the asteroids, and both the asteroid and the beam are destroyed. In their place, however, an explosion particle system prefab is instantiated. Everything works perfectly, except for the fact that two prefabs appear with each destroyed asteroid. Despite being able to play the newest, most demanding games on high or sometimes ultra settings at 60 fps, the two explosions slow my system down like crazy, which doesn't make any sense to me.

Mind you, this is a 3D game. It all takes place in a 2d plane, but I'm using 3D assets, like the ship and the asteroids.

I've tried placing a single explosion in the scene and nothing slows down. Here is the relevant part of the Asteroid script.

 public Transform boomObject; //Assign prefab in inspector
 
 void OnCollisionEnter (Collision other) {
     if (other.gameObject.name == "Beam(Clone)") { //check if collision is with my beam
         Destroy (gameObject);  //destroys asteroid
         Destroy (other.gameObject); //destroys beam
         Instantiate (boomObject, transform.position, Quaternion.identity); //makes  2 explosions?
     }
 }
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

  • Sort: 
avatar image
0

Answer by Bonfire-Boy · Dec 09, 2015 at 07:41 PM

How do you know that the call is creating 2 objects, as opposed to the function being called twice? If you haven't tried this already, add a Debug.Log to your OnCollisionEnter to check this,

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 Hydropulse17 · Dec 09, 2015 at 07:48 PM 0
Share

Oh my god now I feel like an idiot. So I tried the log and confirmed that it was in fact being called twice, and instinctively I checked asteroid prefab for multiple colliders. I don't know how I managed it but each one has two colliders. Thanks for the tip.

Follow this Question

Answers Answers and Comments

40 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

Related Questions

Why all instantiated objects get triggered when 1 is? 0 Answers

Destroying instantiated game objects from prefab when coliding with the ground 1 Answer

ExecuteInEditMode is not working when trying to instantiate a new GameObject [SOLVED] 1 Answer

Instantiating a tile in place of another tile 0 Answers

Instantiation of my GameObjects spell (from other script) 0 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