How to know if a script is being loaded multiple times?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Giannis1996

Hello everyone!
Today i run my test game and i noticed that my game were running slow when i had like 100 kinematic bodies on it
In the game those kinematic bodies autospawn just to destroyed when they hit a wall however i have got a script on those kinematic bodies and maybe the script is loaded one for each body so i think i have like 100 times my script loaded in the game…

my question is

  1. How to know if a script is loaded multiple times (most important)
  2. How to unload the destroyed nodes (mesh texture script) when i don’t need them or when they “die” in game

I need to know those 2 things, there is no reason to load multiple scripts since i can load 1 script on a base node + there is no reason for the destroyed nodes to fill game buffers.

Thank you!

How, exactly, do you load the kinematic bodies? Does the script call load(), and then the bodies are instanced? Concerning destroying the instances: when they collide with something, have them call queue_free() on themselves.

Ertain | 2020-03-14 17:51

:bust_in_silhouette: Reply From: 1izNoob

For number 1: Do you mean how to count the number of bodies in code or do you just want to know for testing purposes? If it is just for testing purposes you can just run the game in the usual way (so either pressing F5 or F6) and while the game is running look at where the node tree used to be. It should now be showing local and remote; and on the remote tab you can see all the nodes in your scene in real time. Insanely useful for testing purposes.

If you want to count them with code, maybe just load the kinematic bodies in an empty node and count the children?

For number 2: queue_free() should take care of that.