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

The simple way is to destroy them right after instantiation.

var obj=Instantiation(prefab, position,rotation);

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.

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! :slight_smile: