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 DanglyButz · Oct 07, 2012 at 06:42 AM · errornewthanks

Removing dead bodies, big lag issue.

'Ok so as I said I am having lag issues because bodies are building up causing lag, can anyone look at this script and tell me what Im doing wrong? and if possible fix it for me? explain it also if you fix it? thanks!'`

var body : GameObject; ---Is supposed to tell that the parent of the script will remove

setTimeout(cleandeadbodies(),4000); ---a timer before the function function cleandeadbodies(){ ---the function body.Parent = nil; ---deletes the ragdoll/dead body }`

Comment
Add comment · Show 1
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 · Oct 08, 2012 at 08:29 AM 0
Share

Actually one thing you could do to avoid lagging is to create a pool of object. It takes a little thinking to implement but the result is worth it.

You create an array of objects with in your case, the objects and the ragdolls. Ins$$anonymous$$d of instatiating and destroying objects you simply deactivate them. Instantiatiation takes a little computation but no big deal while destroying is the harmful one. It takes the garbage collector to check what is used in the memory and what is free. Also, (to be verified I do not know the internal memory management of Unity) it can create fragmentation, which is when memory has unoccupied allocations that are too small to be used.

As pseudo code your pooling could go like this:

-Instantiate 20 enemies in the Start function and place them in an array. Instantiate 20 ragdolls and place them after (index 20-39)

-Now you can activate/deactivate simply keeping track of the index. For instance, array[15] gets killed:

 array[i].active = false;
 array[i+20].active = true;

I just remove the objetc and replaced it with ragdolls. Obviously you would have to position it and so on. But here is the idea.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by fafase · Oct 07, 2012 at 06:48 AM

The simple way is to destroy them right after instantiation.

 var obj=Instantiation(prefab, position,rotation);
 Destroy(obj,20.0f);

Here you create an object (whatever it is), then you place a reference that you use to destroy it.

The second parameter of destroy is a timer. In my example, the object is removed after 20s.

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 DanglyButz · Oct 07, 2012 at 11:38 AM 0
Share

This is really good but does it get attached to the ragdoll and as soon as its spawned gets activated?

avatar image fafase · Oct 07, 2012 at 03:23 PM 0
Share

I do not get what you mean. The reference is just a variable that refers to the actual variable (it refers to...). In my example, obj is a reference to the object instantiated so that you can access it and apply all kind of actions. In this case, we tell the compiler to destroy the obj object after 20s. As the reference exists in this scope, it works. For instance:

 if(something){
   var obj=Instantiation(prefab, position,rotation);
 }
 Destroy(obj,20.0f);

will not work because the obj reference is declared inside the if statement and gets destroyed after }. Still the object will leave. Hopefully, I make sense...

avatar image DanglyButz · Oct 07, 2012 at 03:38 PM 0
Share

Well then how do I make it so it will cleanup the dead ragdoll body 4 seconds after the ragdoll spawns?

avatar image fafase · Oct 08, 2012 at 05:16 AM 0
Share

Change the seconds parameter to 4.0f

avatar image
0

Answer by BlackArcane · Oct 07, 2012 at 06:46 AM

You could try having a master object that will check your scene for dead bodies (using a tag) and removing them after set intervals. Good luck! :)

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

11 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

Related Questions

Multiple Cars not working 1 Answer

Scripting Error! - UCE0001: ';' expected. Insert a semicolon at the end. 1 Answer

Cannot implicitly convert type `float' to `int'. An explicit conversion exists (are you missing a cast?) 2 Answers

Animation spins wildly after completed 0 Answers

NullReferenceException problem 2 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