-
Notifications
You must be signed in to change notification settings - Fork 2
Working with sounds
All sounds of your project should be placed in hammer_project/sound/
folder to be able to preview them in Hammer++. It's not necessary for sounds that won't be used in maps but it's better to keep all sounds in one place, right? ;)
Keep in mind that new sounds should be imported/precached by Godot Engine otherwise they won't work.
There's a singletone class called SoundManager that has several methods to work with sounds. You can extend/change this script to suit your needs.
Before use specific sound you shoud precache it first in _entity_ready
/_ready
method or when the game starts.
# scripts/sound_manager.gd
## Precaches specific sound from `hammer_project/sound`
func precache_sound(sound_path: String): pass;
## Creates AudioStreamPlayer3D in specified position and plays the specified sound
func play_sound(position: Vector3, sound_name: String, volume: float = 1.0, pitch: float = 1.0) -> AudioStreamPlayer3D: pass;
## Creates AudioStreamPlayer3D in specified position and plays one of the specified sounds
func play_random_sound(position: Vector3, sound_list: PackedStringArray, volume: float = 1.0, pitch: float = 1.0) -> AudioStreamPlayer3D: pass;
## Creates AudioStreamPlayer and plays specified sound
func play_everywhere(sound_name: String, volume: float = 1.0, pitch: float = 1.0) -> AudioStreamPlayer: pass;
Assume you want to add some music to the map. Create an entity called ambient_generic
, open its properties and select Sound name
field.
Click Browse
and Hammer will open the sounds browser. In the Sound type
field select Raw
and you'll be able to see all sounds you added in the project.