Hey. This is a simple little trick to de-spawn and re-spawn lights in-game; I never really wondered about this myself too far, but I just now thought about the possibilities of deleting and spawning lights dynamically in-game. So, I thought I’d make a note here about my quick findings in case someone wanders along wondering about it.
You can delete lamps in-game to reduce the load on the Rasterizer. Lamps don’t take up FPS while they’re not spawned (unsurprisingly), so a simple trick to having nice dynamic lighting would be to delete lamps that you’re far away from or looking away from.
You can spawn lamps in-game when you need to. Note that there are a couple of rules to this.
Rule #1. You can only spawn a single lamp once. If it exists in-game already, then you can’t spawn it again.
Rule #2. The lamps need to be in a hidden layer in the same scene that they’re going to be added into in-game. If they’re in another scene (or blend file, I suppose) and linked in via group instances, the process won’t work (they can be added in, but they won’t light the scene).
The solution to spawning a lamp once would just be to create multiple lamps in a hidden layer, and then spawn one that hasn’t been used yet. Of course, this is something you can do with Python. Also note that once a lamp is deleted, it can be re-spawned. So, a pretty simple Python script can just keep track of lamp objects that have been created already and choose one that isn’t already in use when light spawning is needed.
Here’s a blend file to show the example of spawning the lights dynamically in-game, and with that light registry Python script. A good thing about it is that there shouldn’t be any necessary tricks if you want to delete a light. Just delete it, and when you go to re-spawn another one, the script will re-use that light if necessary. I encapsulated the script into a Python function that can easily be adjusted to allow for adjustable color, energy, etc. as necessary.
Note that there is very little performance gains in my example, as they’re just point lamps.