Changing SFXEmitter Volume

Discussion in 'Programming' started by vulcan-dev, Jul 23, 2022.

  1. vulcan-dev

    vulcan-dev
    Expand Collapse

    Joined:
    Jan 28, 2017
    Messages:
    245
    Hello, I've created an SFXEmitter but when setting volume via a custom ImGui UI, it doesn't work. If I look in the editor, the volume is changing but it's not actually updating it.

    Where I'm creating the object
    Code:
                   
                    -- create sound
                    local soundObj = getObject("rain_sound")
                    if not soundObj then
                        soundObj = createObject("SFXEmitter")
                        soundObj.scale = Point3F(100, 100, 100)
                        soundObj.fileName = String('/art/sound/environment/amb_rain_medium.ogg')
                        soundObj.playOnAdd = true
                        soundObj.isLooping = true
                        soundObj.volume = 0
                        soundObj.isStreaming = true
                        soundObj.is3D = false
                        soundObj:registerObject('rain_sound')
                    end
    
    Where I'm updating the volume
    Code:
                if imgui.SliderFloat("Rain Volume", ptr_rain_volume, 0, 1, "%.2f") then
                    soundObj.volume = ptr_rain_volume[0]
                end
    
    Any help would be appreciated :)
     
  2. DaddelZeit

    DaddelZeit
    Expand Collapse

    Joined:
    Jul 17, 2019
    Messages:
    3,319
    Unfortunately sound emitter values can't be updated in real time, the sound always needs to be restarted. Sound emitters are not meant to be dynamic objects, apparently.

    To update, first stop the sound and then play it again:
    Code:
    soundObj:stop()
    soundObj:play()
    
     
  3. vulcan-dev

    vulcan-dev
    Expand Collapse

    Joined:
    Jan 28, 2017
    Messages:
    245
    I've already tried that, sadly it didn't work. For my server on KissMP, I had to fully delete it and then make a new one. I suppose I'll be doing that 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