Jump to content

SoundEmitter.KillSound - sound doesn't stop


Recommended Posts

Hi all,

 

I'm relatively new to the modding scene, been piecing everything together myself but I've run into a bit of a snag. I've made custom sounds for a handslot-equippable item but there's a particular sound I want to run indefinitely while the item is equipped and stop when unequipped.

 

I used the code from the torch.lua as a basis - "inst.SoundEmitter:KillSound("torch")" seems rather straightforward but imitating it in my own code nets no results. The sound plays just fine, but won't stop after I've unequipped the item. (Side note: the sound being killed in torch.lua doesn't include the filepath when being played or killed - seems odd, is this something to do with the issue I'm having?)

 

Has anyone else attempted something similar and has any tips they'd like to share? I've probably just overlooked something simple, but any help would be much appreciated.

 

Thanks in advance!

Link to comment
Share on other sites

@patriciancat,

in "inst.SoundEmitter:KillSound("torch")" the word torch referes to the soundname not the prefabname(not sure if that was clear to u).

so if u start your sound with your own soundpath(which is btw not the folders in the filesystem, but the soundpath from your custom soundfile, see soundtutorial) lets say inst.SoundEmitter:PlaySound("character/character/fart") then u also have to kill it like this: inst.SoundEmitter:KillSound("character/character/fart")

and ofc inst still has to refer to the same entity.

Link to comment
Share on other sites

@Seiai,

Thanks for replying. Yes I do know "torch" refers to the soundname here - The sound is playing correctly, so I don't think the issue is with the filepath. For a clearer example of my code, I have in the OnEquip function:

 

inst.SoundEmitter:PlaySound("xxxx/xxxx/xxxx")

 

which works correctly - the sound plays when the item is equipped. It's meant to be a sort of humming noise, so it plays for a while, but I'm trying to stop the sound from playing too long. So in the OnUnequip function, I have:

 

inst.SoundEmitter:KillSound("xxxx/xxxx/xxxx")

 

which does not stop the sound, hence the issue I'm having. The filepath is identical in both instances, so I can only assume I'm using KillSound incorrectly.

Link to comment
Share on other sites

No, you have to label a sound when playing it.

 

Take Maxwellphonograph.lua as an example.

       inst.SoundEmitter:PlaySound(inst.songToPlay, "ragtime")

[...]
    inst.SoundEmitter:KillSound("ragtime")

 

See?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...