0 votes

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!

in Engine by (67 points)

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.

1 Answer

0 votes
Best answer

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.

by (244 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.