Level of Detail (LOD) Script Problems

Hello everyone.
I’m wondering if there is any way of activating objects (make them perform a function) only when the player can see them.
For example, if you have a fountain that creates heaps of water particles; it’s probably alright to have it going all the time, but if you add multiple fountains (in various locations) it’s probably going to make the game lag. Is there any way of making the fountain only produce water particles when it’s visible (within the viewport)?

Note: This is just an example; the function/event can be anything.

Edit: New problem, relating to a LOD script, see post 5 for details.

That depends on how you create the water. If you use paricles it is most likely not a good idea. Imagine the fountain is slightly out of sight and will not produce water. Then the player turns to the fountain and it starts sparkling. That would look like as it just starts with that not as it already does this.

I suggest to do some kind of LOD. Producing more particles (or more detailed) particles when the fountain is near the camera (regardless if it is in the view frustum or not). If the fountain is behind the camera far clipping distance, you could switch it off completely as long it is not possible to “jump” to the fountain.

I hope it helps

I understand what you mean about the fountain looking like it’s just turned on once you look at it. A Level of Detail script would probably be the right way to go. But so far, everytime I’ve used LOD it creates pernament lag. I suppose it’s a trade-off, pernament constant lag, or a lag that gets worse the more objects you add. Thanks for the tip; I’ll give it a go.

You wouldn’t need LOD for each particle. Just one LOD for the fountain itself.
To make it faster you could use one or more near sensors checking for the camera.
This should be faster than a python script running all the time.

Okay, I’ve been working on a LOD script. I’ve tweaked it so that the further the camera is from an object, a variable called ‘mesh’ will change. For the most part it works.

Except when I add a new object while the game is running, the LOD script won’t recognise the new object, and the variable doesn’t change.
The object and its code is duplicate to other objects using the LOD script.

I think it has something to do with the object list. Is there any way I can get the LOD script to recognise objects created while the game is running? (Or update the object list?)
Here’s the blend file: LodTweaked.blend (102 KB)

PS. Monster: Thanks for your tips. By changing the radar to a near sensor I greatly improved the efficiency of the LOD script.