Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Audio and Music play too early before scene finishes loading.

Discussion in 'Editor & General Support' started by guillopuyol, Apr 8, 2014.

  1. guillopuyol

    guillopuyol

    Joined:
    Jul 16, 2013
    Posts:
    10
    I have a rather large scene.

    I'm playing my music and soundFX on Start(), they are not set to playOnAwake.

    For some reason the music and sound plays even if the scene is not loading... Any ideas on what I should check? or any way to ensure this doesn't happen?


    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class VortexAudio : MonoBehaviour {
    5.  
    6.     private bool _soundEnabled;
    7.     public AudioClip vortexOff;
    8.     public gameController gameController;
    9.  
    10.     // Use this for initialization
    11.     void Start () {
    12.         //Check and Set Sound Enabled State
    13.         _soundEnabled = gameController.soundEnabled;
    14.         this.audio.mute = !_soundEnabled;
    15.  
    16.     }
    17.    
    18.  
    19. }
     
  2. iMob

    iMob

    Joined:
    Apr 9, 2014
    Posts:
    55
    Does it happens on WebPlayer or Standalone? Or everytime?
    If only WebPlayer, take a look at Application.GetStreamProgressForLevel.html

    For other platforms I would try to move your soundEnable-code into Update() to be sure all Start() functions have passed the first time. This gives you some more time.
     
    Last edited: Apr 9, 2014
  3. guillopuyol

    guillopuyol

    Joined:
    Jul 16, 2013
    Posts:
    10
    It's happening on iOS, but I can also notice it in the editor. If I move it into the Update I would have to run that check every frame unnecessarily for the entire level, so I'm trying to avoid that.