I am making a game, but is just a beginner at upbge I learn to do python programming in it and is looking for ways to optimize scripts. Please help.
Most of the time a thread is not what you are looking.
Post the problems you are trying to solve and we can help you break them down.
(for instance upbge has geometry nodes which are threaded for the most part and can do some heavy lifting too)
Vizualize_Attack.blend (141.1 KB)
this has a thread* its used for audio processing / input audio.
Thank you for your response. I looked at your file. not quite sure what it does all the way…im still new at python. I thought threading might be the solution to my problem. In my game I was working on a way to make objects appear and disappear based on the players position to them I looked at your KD_load_object_bubble_0_2_5 to see if that might work, but I couldn’t figure out how to convert my scene into text for it. so I tried to write my own. it works but once it loops through the hundreds of objects the logic turns up and the frame rate drops. Making the Game unplayable. Do you know anyway to help with that?
Side Note:
I have learned a bit more about python from your file though.
Here is the file
testSpawner.blend (2.8 MB)
So, for a start, I love the code. The use of KDTree is a great implementation. When I run it I can maintain 60fps when I take out one(1) thing, and that’s “.addObject()”. The absolute best implementation of something like this in a game would be to make your own subclass, or even complete class, for game objects with less data, and to devise your own addition/subtraction from the scene for that object class.
Maybe if you create your own scene subclass, that instantiates your own game object subclass/original class, you can avoid A LOT of the overhead of the bloated native ‘scene.addObject()’.
But that’s really the big bottle-neck in this case.
That being said, if you’re looking for multi-threading and multi-processing in python, I can recommend some videos on those subjects:
An introduction to multi-processing:
And an introduction to multi-threading:
I’ve been wondering myself if such things as those can be implemented in Blender, and more specifically, UPBGE
There is a example of using a thread to handle mic in resources, I think
Thank you @joelgomes1994 btw*
Thank you i will look at them. I am not sure how to add objects and take them away without the “.addObject()” do you know how perhaps.
Pooling!!
We store them in a list and “check it out” off the list
When we are finished using the object put it back on the list.
Ironically that file does pooling in 3x using mesh edges to draw lines!
Do you have an example I may try please.
Thank you, but I was trying to find out what you meant with pooling. I have never heard of it before.
Ah I found one of your examples for pooling in someone else’s post.https://blenderartists.org/t/help-to-pool-object-in-upbge/1406591
I’m sorry I tried to blend the test spawner script and your pooling script and failed miserably. Would you happen to know how to do that?