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 Valkorian · Apr 03, 2013 at 11:06 PM · destroybulletremove

Cant remove bullets after a set amount of time

I am trying to remove an bullet after a set amount of time but all i get is the error saying it cant delete it due to data loss.

i am using the code

 if (timer >= 4)
 {
      Destroy(Fireball.gameObject);
 }

is there a way to remove the bullet that was fired after the set amount of time.

Comment
Add comment · Show 5
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 Dracorat · Apr 03, 2013 at 11:38 PM 0
Share

I'm new to Unity but an old-hat at C# and it would seem to me that maybe you just need to Destroy(Fireball) ?? I don't know for sure, that's why I'm only posing this as a comment.

avatar image Benproductions1 · Apr 03, 2013 at 11:42 PM 0
Share

What exactly is unity telling you? Data loss is not an error Unity throws, can you paste it in? :)

avatar image Dracorat · Apr 03, 2013 at 11:45 PM 0
Share

Also, by reading the documentation, it appears you can't Destroy a prefab - that's not a prefab is it? (IE, it should be an instance - maybe created FRO$$anonymous$$ a prefab but not the prefab itself) (Using the Instantiate method)

avatar image Benproductions1 · Apr 03, 2013 at 11:48 PM 0
Share

@Dracorat correct, we need more info on what Fireball is and also are you sure that your timer works? Have you one a Debug.Log in the statement?

avatar image Valkorian · Apr 04, 2013 at 09:41 AM 0
Share

Fireball is a prefab and i can get it to fire. i know the timer worked because i only get the error after the set amount of time.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer Wiki

Answer by Dracorat · Apr 04, 2013 at 04:14 PM

Based upon your confirmation that Fireball is a prefab, I think the problem is that you're attempting to use the prefab directly.

In general, your code should be something like this:

 // Inside the class - local variable, public access
 public GameObject Fireball; // In the editor window, drop the Fireball prefab to this

 // In a method ...
 var fireballInstance = Instantiate(this.Fireball);

 //Later, when you're done with it and want it gone
 Destroy(fireballInstance);

You can't destroy the prefab - and you shouldn't be trying to use a prefab directly. If you placed it in your scene - so that it's an instance, be sure to drag the Instance (from the scene graph) to the script reference, not the Prefab (from the project explorer) to the script reference.

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
Wiki

Answer by DryTear · Apr 04, 2013 at 02:04 AM

AutoDestroy.js :

 var ExpireTime : float;

 function Start(){
     yield WaitForSeconds(ExpireTime);
     {
         Destroy(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 Chronos-L · Apr 04, 2013 at 02:38 AM 0
Share

Why not:

 var ExpireTime : float;
 
 function Start() {
    Destroy(gameObject, ExpireTime);
 }

Is there any significant performance difference between the two?

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

14 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

Related Questions

shoot bullet at any direction(random) 0 Answers

Destroy bullet on random collision 2 Answers

C# Destroy tag on collision 1 Answer

Remove trees dynamically - stuck with collider 3 Answers

ON hit remove 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