Stride

OPEN / CLOSE
  • Features
  • Blog
  • Documentation
  • Community
(icon) Download

  • Discord
  • Facebook
  • Twitter
  • YouTube

LANGUAGE

OPEN / CLOSE
  • English
  • 日本語
  • Documentation
  • Manual
  • API
  • Release Notes
  • Tutorials
    Show / Hide Table of Contents
    • Requirements
    • Stride for Unity® developers
    • Stride Launcher
    • Get started
      • Install Stride
      • Visual Studio extension
      • Launch Stride
      • Create a project
      • Game Studio
      • Assets
        • Create assets
        • Use assets
      • Scenes
        • Create a scene
        • Add entities
        • Manage entities
        • Navigate in the Scene Editor
      • Launch a game
    • Animation
      • Import animations
      • Animation properties
      • Set up animations
      • Preview animations
      • Animation scripts
      • Additive animation
      • Procedural animation
      • Custom blend trees
      • Model node links
      • Custom attributes
    • Audio
      • Import audio
      • Audio asset properties
      • Non-spatialized audio
      • Spatialized audio
        • Audio emitters
        • Audio listeners
        • HRTF
      • Stream audio
      • Global audio settings
      • Play a range within an audio file
      • Custom audio data
      • Set an audio device
    • Engine
      • Assets
        • Asset bundles
        • Asset control
      • Entity component model
        • Manage entities
      • File system
    • Files and folders
      • Project structure
      • Cached files
      • Version control
      • Distribute a game
    • Game Studio
      • Scenes
        • Create and open a scene
        • Navigate in the Scene Editor
        • Manage scenes
        • Load scenes
        • Add entities
        • Manage entities
      • Assets
        • Create assets
        • Manage assets
        • Use assets
        • Archetypes
      • Prefabs
        • Create a prefab
        • Use prefabs
        • Edit prefabs
        • Nested prefabs
        • Override prefab properties
        • Prefab models
      • Game settings
        • Splash screen
      • World units
    • Graphics
      • Cameras
        • Camera slots
        • Animate a camera with a model file
      • Materials
        • Material maps
        • Attributes
          • Geometry attributes
          • Shading attributes
          • Misc attributes
          • Clear-coat shading
        • Layers
        • Slots
        • Materials for developers
      • Textures
        • Normal maps
        • Compression
        • Streaming
        • Skyboxes and backgrounds
      • Lights and shadows
        • Add a light
        • Point lights
        • Ambient lights
        • Directional lights
        • Skybox lights
        • Spot lights
        • Light probes
        • Light shafts
        • Shadows
        • Voxel Cone Tracing GI
      • Post effects
        • Anti-aliasing
        • Ambient occlusion
        • Bloom
        • Bright filter
        • Color transforms
          • Film grain
          • Gamma correction
          • ToneMap
          • Vignetting
          • Custom color transforms
        • Depth of field
        • Lens flare
        • Light streaks
        • Local reflections
      • Graphics compositor
        • Scene renderers
          • Custom scene renderers
        • Debug renderers
        • Render textures
        • Render group and masks
      • Effects and shaders
        • Effect language
        • Shading language
          • Classes, mixins and inheritance
          • Composition
          • Templates
          • Automatic shader stage input/output
          • Shader stages
        • Custom shaders
        • Compile shaders
      • Low-level API
        • Textures and render textures
        • Pipeline state
        • Resource binding
        • Draw vertices
        • SpriteBatch
        • SpriteFont
      • Rendering pipeline
        • Render features
        • Render stages
      • Sprite fonts
    • Input
      • Gamepads
      • Gestures
      • Keyboards
      • Mouse
      • Pointers
      • Sensors
      • Virtual buttons
    • Navigation
      • Navigation groups
      • Navigation meshes
      • Navigation bounding boxes
      • Navigation components
      • Dynamic navigation
    • Particles
      • Create particles
      • Emitters
        • Shapes
          • Ribbons and trails
        • Materials
        • Spawners
        • Initializers
        • Updaters
      • Tutorials
        • Particle materials
        • Inheritance
        • Lasers and lightning
        • Create a trail
        • Custom particles
    • Physics
      • Colliders
        • Static colliders
        • Rigidbodies
        • Kinematic rigidbodies
        • Characters
        • Collider shapes
        • Triggers
        • Constraints
      • Raycasting
      • Simulation
      • Tutorials
        • Create a bouncing ball
        • Script a trigger
    • Platforms
      • Linux
        • Setup and requirements
        • Create a Linux game
      • UWP
        • Xbox Live
      • iOS
      • Add or remove a platform
      • Set the graphics platform
    • Scripts
      • Types of script
      • Create a script
      • Use a script
      • Public properties and fields
      • Scheduling and priorities
      • Events
      • Debugging
      • Preprocessor variables
      • Create a model from code
    • Sprites
      • Import sprite sheets
      • Edit sprites
        • Set sprite borders
      • Use sprites
    • UI
      • Pages
      • Libraries
      • Editor
      • Add a UI to a scene
      • Layout system
    • Video
      • Set up a video
      • Video properties
      • Video scripts
      • Use a video as a skybox
    • Virtual reality
      • Enable VR
      • Preview a scene in VR
      • Overlays
        • Display a UI in an overlay
      • VR sickness
    • NuGet
      • Consume Packages
      • Create Packages
    • Troubleshooting
      • Logging
      • Debug text
      • Profiling
      • Stride doesn't run
      • Default value changes ignored at runtime
      • Lights don't cast shadows
      • Full call stack not available
      • Error: "A SceneCameraRenderer in use has no camera assigned to its [Slot]. Make sure a camera is enabled and assigned to the [Slot]"
    • Manual
    • Audio
    • Spatialized audio
    • Audio emitters

    Audio emitters

    Beginner Programmer Designer

    Audio emitter components emit audio used to create spatialized audio. You can add them to any entity.

    The pitch and volume of the sound changes as the audio listener moves closer to and away from the audio emitter.

    Note

    You need at least one AudioListenerComponent in the scene to hear audio from audio emitters.

    1. Set up an audio emitter asset

    1. In the Scene view, select an entity you want to be an audio emitter.

      Select an entity

    2. In the Property Grid, click Add component and select Audio Emitter.

      Add AudioEmitter Component

      Now we need to add audio to the emitter.

    3. Under Audio Emitter, click Green plus button (Add) and specify a name for the audio.

      Add new sound entry

    4. From the Asset View, drag and drop an audio asset to the audio you just added:

      Drag and drop an audio asset

      Alternatively, click Hand icon (Select an asset).

      Pick up an asset

      Then choose an audio asset:

      Select audio  asset

    5. Repeat steps 3 and 4 to add as many audio assets as you need.

    6. Configure the properties for this audio emitter.

      Audio emitter properties

    Property Description
    Use HRTF Enable head-related transfer function (HRTF). With this enabled, sounds appear to come from a specific point in 3D space, synthesizing binaural audio. For more information, see HRTF.
    Directional factor How directional the audio is, from 0 (min) to 1 (max). If set to 0, the audio is emitted from all directions. You can control this with a slider or number value.
    Environment The reverb type for the audio, simulating reverberation of real environments (small, medium, large, or outdoors).

    2. Create a script to play the audio

    Now we need to create a script to play and configure the audio asset.

    1. In your script, instantiate AudioEmitterSoundController for each sound you want to use in the script.

      For example, say we have two sounds, MySound1 and MySound2:

      AudioEmitterComponent audioEmitterComponent = Entity.Get<AudioEmitterComponent>();
      AudioEmitterSoundController mySound1Controller = audioEmitterComponent["MySound1"];
      AudioEmitterSoundController mySound2Controller = audioEmitterComponent["MySound2"];
      
    2. Use the following AudioEmitterSoundController properties and methods to play and configure the audio:

    Property / method Description
    IsLooping Loops audio. Has no effect if PlayAndForget() is set to true.
    Pitch Gets or sets sound pitch (frequency). Use with caution for spatialized audio.
    PlayState Gets the current state of the audio emitter sound controller.
    Volume Volume of the audio.
    Pause() Pauses audio.
    Play() Plays audio.
    PlayAndForget() Plays audio once, then clears the memory. Useful for short sounds such as gunshots. Overrides IsLooping.
    Stop() Stops audio.

    For example:

    mySound1Controller.IsLooping = true;
    mySound1Controller.Pitch = 2.0f;
    mySound1Controller.Volume = 0.5f;
    mySound1Controller.Play();
    

    This sound will loop at double the original pitch and half the original volume. For more information, see the AudioEmitterSoundController Stride API documentation.

    3. Add the script to the audio emitter entity

    Game Studio lists the script as a component under Add component. Add the script to the audio emitter entity.

    1. In the Scene view, select an entity you want to be an audio emitter.

      Select an entity

    2. Click Add component and select the script.

      Add audio script

    See also

    • Spatialized audio
    • Audio listeners
    • Global audio settings
    • Improve this Doc
    In This Article
    In This Article
    • 1. Set up an audio emitter asset
    • 2. Create a script to play the audio
    • 3. Add the script to the audio emitter entity
    • See also

    Back to top

    Copyright © 2019-2021 .NET Foundation and Contributors
    Supported by the .NET Foundation