Unable to set light's energy at runtime with Python

Hi,
working with UPBGE 0.30.0 alpha here.
I need to set and get the energy of a light at runtime. I tried with:

import bge
scene = bge.logic.getCurrentScene()
light = scene.lights["L1_obj"]
print(light.name) # prints correct name, so light object is being found
print(light.energy) # throws exception: KX_LightObject has no attribute 'energy'
print(help(light)) # tried also print(dir(light))

If I’m not mistaken, according to the documentation:


the attribute ‘energy’ should exist, and is also used in the examples.
What am I missing?

Hello,
The docs are outdated and under maintenance atm. Apologies for that.

BGE API.

bge.logic.getCurrentScene().lights["Sun"].blenderObject.data.energy = 0.0

BPY API.

bpy.data.lights["Sun"].energy = 0.0

Either way works, but the BPY approach might cause some errors depending on what your using it for and how you use it.

More info here.

1 Like

Additionally to @RandomPanda said, the official documentation is:


In that documentation you can see that KX_LightObject doesn’t have any attribute now.

Apart from that, we have to add several examples to the doc

2 Likes

Hi,

bge.logic.getCurrentScene().lights["Sun"].blenderObject.data.energy = 0.0

solved the problem, thank you!

1 Like