Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by PvtDancer · May 29, 2015 at 05:46 AM · audioaudiosourcemixingplayclipatpoint

How to route sound from PlayClipAtPoint() to a specific audio mixer group?

The only other answer I've found to a similar problem is to add the mixer as a public variable. But this can't be done when using PlayClipAtPoint().

I've tried to write my own public static method that does what PlayClipAtPoint does, but I can't change the audio mixer group in the script after adding the audiosource component.

Any ideas on how to achieve this? Thanks!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by neekoh · Jun 23, 2016 at 02:13 PM

Hi,

I don't know why you can't change the outputAudioMixerGroup after adding the audio source. Also, PlayClipAtPoint() also uses default values for all AudioSource parameters for the temporary objects it makes, so if you want some specific behaviour, PlayClipAtPoint() is not very useful.

But with your replacement method you can do this:

  • Create a set of prefabs of gameobjects that have an AudioSource component

  • In the prefabs you can set different mixer groups and other AudioSource settings

  • In you replacement method instantiate one of these prefabs as your temporary audio source depending on situation. Something like:

        GameObject audioObject;
         if (type == AudioType.Announcer)
             audioObject = Instantiate(announcerAudioPrefab);
         else
             audioObject = Instantiate(worldAudioPrefab);
    
         audioObject.transform.position = position;
         AudioSource tAudio = audioObject.GetComponent<AudioSource>();
         tAudio.clip = clip;
         tAudio.Play();
    
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by FColor04 · Dec 30, 2021 at 07:23 PM

It's old question but for anyone still wondering, static method

PlayClipAtPoint
looks like this:
public static void PlayClipAtPoint
(AudioClip clip, Vector3 position, [DefaultValue("1.0F")] float volume)
    {
      GameObject gameObject = new GameObject("One shot audio");
      gameObject.transform.position = position;
      AudioSource audioSource = (AudioSource) gameObject.AddComponent(typeof (AudioSource));
      audioSource.clip = clip;
      audioSource.spatialBlend = 1f;
      audioSource.volume = volume;
      audioSource.Play();
      Object.Destroy((Object) gameObject, clip.length * 
((double) Time.timeScale < 0.009999999776482582 ? 0.01f : Time.timeScale));
    }

And after some modifications I've got this in result:


public static void PlayClipAtPoint
(AudioClip clip, Vector3 position, float volume = 1.0f, AudioMixerGroup group = null)
        {
            if (clip == null) return;
            GameObject gameObject = new GameObject("One shot audio");
            gameObject.transform.position = position;
            AudioSource audioSource = (AudioSource) gameObject.AddComponent(typeof (AudioSource));
            if(group != null)
                audioSource.outputAudioMixerGroup = group;
            audioSource.clip = clip;
            audioSource.spatialBlend = 1f;
            audioSource.volume = volume;
            audioSource.Play();
            Object.Destroy(gameObject, clip.length * 
(Time.timeScale < 0.009999999776482582 ? 0.01f : Time.timeScale));
        }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Is it possible to expose the output of a Unity Audio Mix Bus as an AudioSource? 0 Answers

GoogleVr Audio Audiosource - Output 1 Answer

Get spectrum data from specific Audio Mixer? 1 Answer

Is there a way to limit the output volume on an audio mixer group? 1 Answer

Making AudioSource follow camera? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges