Upbge: Change Light Color/Energy in game

Created on 11 Feb 2020  Â·  13Comments  Â·  Source: UPBGE/upbge

I don't know if the attribute is simply accessed differently since 2.8, but changing light attributes doesn't seem to affect the scene anymore

File:
set_light_color.zip

goes for both color and energy

Most helpful comment

All 13 comments

I think you have to adjust the bpy object attributes*

lamp.blenderObject *

On Tue, Feb 11, 2020 at 7:12 AM Leopold A-C notifications@github.com
wrote:

I don't know if the attribute is simply accessed differently since 2.8,
but changing light attributes doesn't seem to affect the scene anymore

File:
set_light_color.zip
https://github.com/UPBGE/upbge/files/4186391/set_light_color.zip

goes for both color and energy

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/UPBGE/upbge/issues/1124?email_source=notifications&email_token=ABW3SWN425GM5L54ZT5TLU3RCK54BA5CNFSM4KTCVLGKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IMS3R2Q,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABW3SWNUN2FXBRFJ62UAR7LRCK54BANCNFSM4KTCVLGA
.

well, it should be the same via bpy as via bge, as both bpy.types.Light and bge.types.KX_LightObject have the attributes energy and color

I don't think they are linked up yet*

On Tue, Feb 11, 2020 at 8:21 AM Leopold A-C notifications@github.com
wrote:

well, it should be the same via bpy as via bge, as both bpy.types.Light
and bge.types.KX_LightObject have the attributes energy and color

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/UPBGE/upbge/issues/1124?email_source=notifications&email_token=ABW3SWKKTLDCHKVK44MUOFTRCLF7FA5CNFSM4KTCVLGKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELNBOVY#issuecomment-584718167,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABW3SWICRBKGRH6LVKL377DRCLF7FANCNFSM4KTCVLGA
.

at the moment , changing properties of the bge objects module does not affect the scene itself. you must change the propreties from the bpy module , then refresh the scene. updating properties from bpy module it's a little bit heavy for the engine.

https://github.com/UPBGE/upbge/issues/1112

before to open an issue take your time for reading the latest closed issue. maybe another asked the same ;)

Actually, I strongly recommend to use Python Tooltips in User Preferences > Interface:

Sans titre

If you do changes only with bpy, but that nothing is moving in the scene, you need to validate the changes with:

IMPORTANT

bge.logic.getCurrentScene().resetTaaSamples = True #to call each time you do something with bpy only

IMPORTANT TOO

In 2.8 bge, KX_GameObject is just a "container for a Blender Object.
you can access this Object like that:

kxscene = bge.logic.getCurrentScene()
kxob = bge.logic.getCurrentController().owner
ob = kxob.blenderObject

From there you can extrapolate:
kxLight = bge.logic.getCurrentScene().objects["Point"]
obLight = kxLight.blenderObject
def increaseLightPower():
obLight.energy += 0.1
kxscene.resetTaaSamples = True

Alright, seems I didn't draw the line from #1112 to light attributes, whoopsi!
I'll get the code updated, then, thanks a lot :)

EDIT: Can't seem to get it to work, it's doing resetTaaSamples, but the color doesn't change and for energy I get the Traceback 'Object' object has no attribute 'energy'

I'm adding all these new tips under Release notes page (to be formatted later).
If anyone is interested in helping with documentation, please let me know and I will give you rights.

haha, yes, sorry, because it is bpy.data.lights and not bpy.data.objects

It should work if you use the code from the python tooltip @IzaZed : )

@lordloki : my example for blenderObject was not very good... lol

light is maybe blenderObject.data ? I'd need to test

yes, light is blenderObject.data

Then you can do:

light = kxob.blenderObject.data
light.energy += 100 #test with light.color[2] -= 0.01 too
bge.logic.getCurrentScene().resetTaaSamples = True

You're incredible youle!
I do work with python tooltips all the time, to be honest I'm currently writing the docs for the logic nodes and just noticed that the light nodes didn't do anything.
Guess now they will

Closing this

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marechal-p picture marechal-p  Â·  6Comments

IzaZed picture IzaZed  Â·  6Comments

RomStef picture RomStef  Â·  6Comments

maconbot picture maconbot  Â·  5Comments

EndSSgamesStudio picture EndSSgamesStudio  Â·  7Comments