I have this Sun lamp in my scene. I need to toggle the visibility of the lamp with the press of a button. I tried using the Visibility actuator, but it does not remove my lamp because visibility in the Physics panel does not apply to lamp values. I thought of a few ways of toggling the visibility of it, but could not get any of them working:

  • Move lamp to another layer on the same scene
  • Delete lamp and re-spawn it (I tried endObject() but it would never remove the object)
  • Change the lamp's brightness value

Remember, this is going to be on a button, so it has to be re-spawnable. If I could get the base code, I can make the toggleable if block myself. Also, this is a Python question. Logic blocks take more time to setup than just a simple script. ;)

Thanks in advance!


In python you can access the lamps energy attribute like this:

bpy.data.objects["Lamp"].data.energy = 0

In the game engine you can toggle the energy by this script (assumes energy value set to 1.0):

co = bge.logic.getCurrentController()
lamp = co.owner
toggle = co.sensors["space"] # space is the name of keyboard sensor

if toggle.positive:
    lamp.energy = 1 - lamp.energy

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.