I tried destroying a character and noticed that it was extremely laggy. I tested it with a fresh baseplate that just simply destroys the animate script of a rig I placed down and I was able to replicate the lag. Below is a screen shot where the micro profiler shows the lag spike. Is lag when destroying a character with an animate script simply unavoidable or is there a better way to destroy characters?
Instead of destroying it, you could add a local script with the same name in StarterCharacterScripts, you could leave it empty which should not make any bugs appear.
I want to destroy this local script not to disable animations but to cleanup a rig. I want to keep a player’s limbs after they die but not the rest of the model. I could just not delete the animate script but over time there would then be lots of animate scripts piling up which probably won’t be that bad for performance but it irks me
I want to destroy a model because I can’t have models sitting around forever. Those models have animate scripts, so when I destroy those models, the animate scripts are destroyed. Destroying a script is laggy. So when I destroy a model I want to destroy, there will be a big lag spike.
Are you destroying it from the client or the server? Destroying an NPC model takes a good amount of computational resources because it first has to destroy every child of any child that has elements within it. It’s better to not destroy them for this reason alone, and you should either re-parent it to something else and destroy them from the server later.