[SOLVED] Change "glow" property of material at runtime

Discussion in 'Programming' started by AlexKidd71, Apr 14, 2024.

  1. AlexKidd71

    AlexKidd71
    Expand Collapse

    Joined:
    Mar 16, 2022
    Messages:
    513
    Hi,
    in my mainLevel.lua I already have code for switching on and off lightsources by daytime.

    I have a couple of TSStatic items which make use of the glow property at stage 0 in materials. Is it possible to switch the glow property to false(0) or true(1) in the
    onUpdate() function?

    Like
    local mat = scenetree.findObject(matName)
    mat:setField('glow', 0, 0)
    or
    mat:setField('glow', 0, 1)

    and refresh the material? In material editor you can switch this property without problems.
    I'm just happy that I got the VS Code debugger running but I have no luck with this at the moment. It's my very first lua experience, haha!

    Best!
    Alex
     
  2. stefan750

    stefan750
    Expand Collapse

    Joined:
    Sep 15, 2013
    Messages:
    22
    You can call the functions
    Code:
    mat:flush()
    mat:reload()
    after changing the properties to update the material
     
    • Like Like x 2
  3. AlexKidd71

    AlexKidd71
    Expand Collapse

    Joined:
    Mar 16, 2022
    Messages:
    513
    Yay! That’s great! Thanks a lot.
     
    • Like Like x 1
  4. AlexKidd71

    AlexKidd71
    Expand Collapse

    Joined:
    Mar 16, 2022
    Messages:
    513
    I just implemented it and it works perfectly. I was worried that it’s very hard on the performance but it fluently changes the glow of the materials. It’s a nice effect if some windows in buildings have a glow effect at night. It’s not so easy to do with the light sources in BeamNG. Thanks again!
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice