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
1
Question by Sarnum · Mar 21, 2012 at 01:33 PM · instantiateprefabdestroyshuriken

Destroying an instantiated prefab particle effect

I have a global inspector variable and I can declare it either this way:

 var explosion       :GameObject;

or this way

 var explosion       :Transform;

I then also have an explosion effect made with SHURIKEN tied to my script via the inspector.

When I call on this explosion I instantiate it like this (in the place of my object), to make sure that explosion is there in the inspector

 if(explosion)
 {
 Instantiate(explosion,transform.position,transform.rotation);
 }


How do I remove the effect after it has done its job ?

I tried:

 if(explosion)
 {
 Instantiate(explosion,transform.position,transform.rotation);
 Destroy(explosion.gameObject,3);
 }


and I got:

Destroying assets is not permitted to avoid data loss.

Does anyone have an idea ?

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

4 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Jason B · Mar 21, 2012 at 03:03 PM

 if(explosion)
 {
 GameObject newexplosion = (GameObject)Instantiate(explosion,transform.position,transform.rotation);
 Destroy(newexplosion,3);
 }

You need to store what you instantiated in a temporary variable so that you can talk to it afterwards.

Comment
Add comment · Show 4 · 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 by0log1c · Mar 21, 2012 at 03:06 PM 0
Share

+1. You may not use Destroy(explosion) as the explosion variable points to the actual asset and not an instance of that asset. Store the instance on creation and destroy that later.

avatar image Sarnum · Mar 21, 2012 at 03:09 PM 0
Share

Thanks, that did it! $$anonymous$$udos and a cookie to You Sir!

avatar image Almondega · Sep 11, 2012 at 12:27 AM 0
Share

Using GameObject didn't work to me to destroy the explosion. If I cast the Instantiate with "as GameObject", the Destroy won't do anything. If I cast like you said, I get this error using C#:

InvalidCastException: Cannot cast from source type to destination type.

But Instantiating to a Transform, and Destroying the transform.gameObject worked just fine :)

Thanks for this tip.

avatar image theAwesomeBlackson · Dec 29, 2015 at 05:52 AM 0
Share

Thank you, this solve one of my issue :) I'm not sure how the reward works but here's a love heart <3

avatar image
0

Answer by Sarnum · Mar 21, 2012 at 03:56 PM

I'm very sorry but I'm using Shuriken particle system and not the old legacy elipsoid particle emitter that had the autodestruct button. If I used the old one I wouldn't have that problem but I do not want to use an outdated system while learning unity 3.5.

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 fafase · Mar 21, 2012 at 07:35 PM 0
Share

No worries.

avatar image
0

Answer by citizen_rafiq · Oct 27, 2012 at 12:27 AM

1.unchecked looping from particle system editor 2.create a transform variable in your script as public(example explosionTrans)and set your particle object from editor. 3.now in your update method explosionTrans.particleSystem.transform.position=this.transform.position; explosionTrans.particleSystem.Play();

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
avatar image
0

Answer by ramp · Jan 28, 2013 at 06:19 AM

if(explosion) { var newexplosion : GameObject = Instantiate(explosion,transform.position,transform.rotation); Destroy(newexplosion,3); }

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

10 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

Related Questions

How many time does a prefab takes to load?? 1 Answer

How to spawn a new prefab when the last one was destroyed?? 2 Answers

Trouble with destroying an instantiated prefab 2 Answers

help for start my project... 2 Answers

Destroying Objects. 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