Search Unity

[RELEASED] SECTR AUDIO: Immersive, Spatial Audio

Discussion in 'Assets and Asset Store' started by MakeCodeNow, Feb 21, 2014.

  1. AdamGoodrich

    AdamGoodrich

    Joined:
    Feb 12, 2013
    Posts:
    3,623
    Hey everyone,

    We are very excited to have SECTR joining the Procedural Worlds family today!

    Over the next few months we will work together with the author of SECTR to familiarize ourselves with the code base and ensure that the same high standard of customer support that both SECTR’s existing customers and Procedural Worlds customers enjoy is maintained.

    For existing SECTR customers, please be assured that your investment is in good hands! We are working with Unity to migrate SECTR over to the Procedural Worlds publisher account. Your existing purchase is safe and when the migration is complete the changeover will be seamless.

    Moving forward, we will continue to develop SECTR, and will also integrate it into our suite of products as part of our commitment to continually enhance the Procedural Worlds content generation and delivery pipeline.

    You can learn more about Procedural Worlds at our web site here: http://www.procedural-worlds.com/

    Cheers,
    Adam.
     
    hopeful likes this.
  2. adam10603

    adam10603

    Joined:
    Aug 13, 2018
    Posts:
    2
    Not sure if this is the right place to ask for help, but I'm having a slight issue with SECTR Audio.

    Basically I need to play two cues at the same time on the same game object, both are just one shot sounds, so my code is simply just two consecutive calls to
    SECTR_AudioSystem.Play()
    . Each one has a different falloff curve set up, the idea being that you'd hear one or the other cue being slightly louder the closer or farther away you are from the object.

    My issue is that only one of the cues seems to be playing at any given time. For some reason SECTR only plays the one which is suppsed to be louder at the time based on its falloff curve, bot not both at the same time, which is really weird. Each time I clearly make two calls to
    SECTR_AudioSystem.Play()
    asking to play each cue, so I don't really understand this.

    I tried adjusting culling options and such, but I had no luck with any of the options I tried. Is this supposed to be this way? Or is there perhaps some other method of achieving the same effect? That is having two cues playing at the same time on the same game object, and the blend between them depends on listener distance.

    Any help would be appreciated! :)
     
  3. frankslater

    frankslater

    Joined:
    May 9, 2016
    Posts:
    103
    Hi @adam10603 ,

    I was curious and looked at this. Sorry if I'm not giving the best answer. This afternoon was actually my first time trying out SECTR Audio.

    By reading your post I get the feeling that you are trying to use spatial audio, but you are playing the cues on the AudioSystem itself (hence not using any spatial data). So you are playing the cues on the "Audio listener" itself (a little bit like playing sounds through a headphone straight in your ears, instead of attaching speakers to objects in the world).

    Did I get close to what you have there?

    Here is what I did to try this, in case it helps:

    1. Created two SECTR Audio Sources - so I can handle the two audio better(falloffs etc.)
    2. Made one of them the child of the other one - to be able to handle them as a single object
    upload_2018-8-17_21-29-35.png
    3. Wrote this quick script to do something like what you want and attached it to my camera/player:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class audioDistancePlayer : MonoBehaviour {
    4.  
    5.     [SerializeField] SECTR_AudioSource source1;
    6.     [SerializeField] SECTR_AudioSource source2;
    7.    
    8.     void Update () {
    9.         if (Input.GetMouseButtonDown(0))
    10.         {
    11.             source1.Stop(true);
    12.             source2.Stop(true);
    13.             source1.Play();
    14.             source2.Play();
    15.         }
    16.     }
    17. }
    4. Assigned the two Game Objects with the SECTR Audio Sources
    upload_2018-8-17_21-43-49.png

    I hope this helps you move ahead in your project.
     
  4. adam10603

    adam10603

    Joined:
    Aug 13, 2018
    Posts:
    2
    @frankslater

    Thanks for the reply!

    Originally I wanted to make a new audio source for each time the sounds play, because that can occur faster than the duration of the cues, and I thought simply resetting the playhead in that case wouldn't sound great. But I tried it, and it sounds just fine, so this solves my issue.
    Thanks!
     
    frankslater likes this.
  5. frankslater

    frankslater

    Joined:
    May 9, 2016
    Posts:
    103
    Lovely stuff @adam10603!
    You can also try removing
    Code (CSharp):
    1.             source1.Stop(true);
    2.             source2.Stop(true);
    to listen if it's something you want. I'm stopping them there first because I didn't want a canon effect
    (like in canon singing/music)

    Depending on your use case, not stopping the previous playback (just playing the next one on top) could be what you need.

    Best of luck!
     
    Last edited: Aug 19, 2018
  6. frankslater

    frankslater

    Joined:
    May 9, 2016
    Posts:
    103
    Hey @adam10603,

    Looking at the AudioSystem API, I found that your idea was correct. There is an option to provide a position where the AudioSystem will play a cue. For me this also works well and thought you might prefer it, if it works for you too:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class AudioDistancePlayer : MonoBehaviour {
    4.     [SerializeField] private Vector3 position;
    5.     [SerializeField] private SECTR_AudioCue cue1;
    6.     [SerializeField] private SECTR_AudioCue cue2;
    7.  
    8.     void Update () {
    9.         if (Input.GetMouseButtonDown(0))
    10.         {
    11.             SECTR_AudioSystem.Play(cue1, position, false);
    12.             SECTR_AudioSystem.Play(cue2, position, false);
    13.         }
    14.     }
    15. }
     
  7. frankslater

    frankslater

    Joined:
    May 9, 2016
    Posts:
    103
    In fact I looked at the documentation and it says
    upload_2018-8-19_18-22-59.png

    so I actually gave you @adam10603 a pretty bad advice there first. :oops::)

    The short code in my last comment uses a much simpler and actually recommended method.
    I hope it works for you!
     
  8. AdamGoodrich

    AdamGoodrich

    Joined:
    Feb 12, 2013
    Posts:
    3,623
    SALE SALE SALE!!!

    All Procedural Worlds Assets Are on Sale for 25% off - Including our recent SECTR acquisition!!

    Plus - to sweeten the deal - we also have a stellar bunch of updates!!

    Gaia 1.8.0 update is live:
    • Added Mac 16 bit raw import
    • Added 8 bit raw file import
    • U2018 related fixes due to changed API's related to spawning prefabs
    • Turned off automatic lightmap baking when creating news scenes
    • Improvement to bounds based collision checking
    • Added Terrain Utilities to Main menu to highlight it
    • Reorganised More menus to make them more understandable
    • Minor usability tweaks
    GeNa 2.0.0 Upgrade is live ($20 for purchases > 90 days ago, free otherwise):
    • Paintbrush painting mode
    • New layer based spawning system & improvements
    • Vastly improved bounds based collision checking
    • Vastly improved rotation algorithm when doing fences
    • New Min and Max spawn height capability & visualizations
    • Height offset modification for collisions
    • Seamless support for SECTR
    • Preliminary Vegetation Studio support
    • Improved help system
    • Fully 2018.x compatible
    • Better defaults.
    CTS 1.8.0 update is live:
    • New material & shader caching system
    • Use of material enable materials shared between terrains
    • New cached shader id system to speed up updates
    • Better registration / deregistration system for multitile
    • Component menu workarounds : CTS moved to GameObject menu
    • Terrain now world space instead of vertex space (prelude to mesh blending)
    • Improved terrain normals generation
    • Moves shaders from Resources to Shaders directory to stop excessive compile times . Reorganised texture and profile directories
    • Latest shader updates / amplify bug fixes
    SECTR will be updated in next few days (currently in test)
    • Seamless support for Gaia terrains
    • Seamless support for CTS
    • New suite of Video Tutorials
    With all this new coolness, a bunch of new video tutorials will also come out later this week...

    HUMBLE BUNDLE SALE

    If you haven't already heard about it then do yourself a favor and check out the amazing Humble Bundle Sale! $15 gets you a bunch of cool games, a set of game dev courses valued at $600, and a whole bunch of premium unity assets.
     
    Last edited: Sep 7, 2018
  9. Xefier

    Xefier

    Joined:
    Dec 22, 2012
    Posts:
    70
    My game instantiates the player at runtime resulting in none of the audio playing and a bunch of Warnings
    "[Warning] [SECTR_AudioSystem] [0.120] (11) Cannot play sounds before SECTR_AudioSystem is initialized.".

    But all of these are ambient audio loops, why wouldn't audio sources simply start playing once the AudioSystem has initialized?
     
    Last edited: Dec 13, 2018
  10. Xefier

    Xefier

    Joined:
    Dec 22, 2012
    Posts:
    70
    I wrote my own solution but seems weird that something like this wouldn't already be supported.
    Especially since it's something Unity Audio has always supported.
     
  11. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    SECTR audio is pure script and so it has limitations that unity audio (which is written into the C++ playe) doesn't have.
     
  12. Xefier

    Xefier

    Joined:
    Dec 22, 2012
    Posts:
    70
    Except it took me less than 10 minutes to write a fix that resolves this limitation so there's no excuse.
    Otherwise the asset is pretty good so far, I just hope I don't have to write any more code for it.
    So far my rating is 4/5, lower if I run into more issues.
     
  13. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    What approach did you take to fix the problem?
     
  14. Xefier

    Xefier

    Joined:
    Dec 22, 2012
    Posts:
    70
    I implemented a WhenReady method to the audio system that immediately executes if initialized otherwise it fills a static action queue, then once it has initialized it processes all the pending actions. The audio source play on start logic is surrounded by the WhenReady call so that it will execute when the system is ready.

    I could send you the changes if you'd like, it's a very small amount of code.
    I just solved the 1 issue I had with it but the concept could be applied at a larger scale (Which I don't have time to do). A few extra things that should be added is verifying that the audio source GameObject hasn't been destroyed, etc.
     
  15. MakeCodeNow

    MakeCodeNow

    Joined:
    Feb 14, 2014
    Posts:
    1,246
    Thanks for sharing. Sounds like a good solution. I no longer maintain SECTR myself but will give the new owners a heads up about your offer.
     
  16. malrion

    malrion

    Joined:
    Dec 23, 2016
    Posts:
    8
    Does Sectr Audio work with FMOD studio, and the the HLAPI that is provided as a unity package? I know at a low level it does interface with FMOD, since FMOD is Unity's audio backbone, but I was thinking more in terms of events, triggers, etc, that I am programming using the higher level integration available on FMOD's website.
     
  17. PWPeter

    PWPeter

    Joined:
    Dec 16, 2018
    Posts:
    383
    No, Sectr Audio uses an optimized pool of Unity Audio Source instances for playback.
     
  18. Lesnikus5

    Lesnikus5

    Joined:
    May 20, 2016
    Posts:
    60
    Hello! For some reason I did not find a playable demo. Can you publish it so that I can try SECTR AUDIO? If possible, Windows standalone build.
     
  19. PWPeter

    PWPeter

    Joined:
    Dec 16, 2018
    Posts:
    383
    Sectr Audio comes with 3 demo scenes, I was about to make a build available for you to download but I noticed there was an issue with the character controller that only appears in the build, not in the editor. I will fix this & upload a build for you shortly.
     
    Lesnikus5 likes this.
  20. PWPeter

    PWPeter

    Joined:
    Dec 16, 2018
    Posts:
    383
    Fixed the issues with the character controller and put the three demo scenes in a single build, here is the download:

    https://drive.google.com/open?id=1VH5TkaaeiNahmA191qlMIRBAk3aUClX8

    You can now switch between the demo scenes with F1, F2, F3 on the keyboard. Additional keyboard commands will be displayed if available.

    Some notes on the different scenes:

    Environment Scene:
    This scene demonstrates how one can setup different audio environments in different sectors, so that they each have their own audio atmosphere. Notice how the sound is blending seamlessly between the rooms and that the background noises consist of multiple audio files each.

    Audio Sources Scene:
    This scene demonstrates the different type of Audio Sources in SECTR Audio. The different types demonstrated are:
    • Point Source: Plays a sound at a 3D point. Very similar to the Unity Audio Source.
      Demonstrated by the bird sounds in the green room
    • Region Source: Plays a sound at a point on a collider nearest to the Listener. Great way to represent volumetric sounds.
      Demonstrated by the wind sounds in the blue room
    • Spline Source: Plays a sound at a point on a 3D spline nearest to the Listener. Very useful for rivers and roads and the like.
      Demonstrated by the flowing water noise that follows you between the yellow and red room
    • Propagation Source: This source models how audio bounces around through an environment. Sounds amazing, but requires Sectors and Portals to work.
      Demonstrated by the techno music in the orange room
    • Door Audio: Plays different audio cues for gameobject with an "opening and closing" animation
      Demonstrated by the sliding doors
    • Impact Source: Plays sounds when a rigid body collides with the world. Great way to tie sounds into the physics.
      Demonstrated by the Sound cubes that you can throw with the "T" key
    HDR mixing Scene:
    This scene demonstrates the HDR mixing in SECTRAudio. Notice how the techno music is blended in an out according to your relative position to the doorways. Also you can play back sounds with the 1-4 keys on your keyboard to see how these sounds are mixed together with the music while respecting the relative loudness of the sound. If you are more interested in this feature you can read more about it in the SECTR Audio manual: https://www.sectr.co/uploads/2/5/7/9/25793991/sectr_audio_manual.pdf
     
  21. PWPeter

    PWPeter

    Joined:
    Dec 16, 2018
    Posts:
    383
  22. netpost

    netpost

    Joined:
    May 6, 2018
    Posts:
    135
    Hi,

    SECTR audio seems like a great tool.

    But i have a problem when trying to do the basic like adjusting level for different sounds in the sector audio window. For example, I have a cue with both the chatter and drop sound in it. If i set the Chatter volume to ".1", I hear the sound volume at the lowered level while pressing the audition button but if I go back and play the chatter sound directly with the speaker at the left of the chatter sound the level is still at maximum (1) . It is a bit unconvenient when you think you lowered the level of a gun shot but then audition from two different places and hear the sound 10 time louder than you set it just a few seconds before. I am using Unity 2018.

    Thanks for your help.
     
  23. PWPeter

    PWPeter

    Joined:
    Dec 16, 2018
    Posts:
    383
    Hi, thanks for the praise! The problem you encountered is pretty much "by design": The Audition button is used to play back the entire Audio Cue under consideration of its settings (volume, pitch, if there is random clips set up in the cue a random clip will be selected, etc.).
    The speaker button next to a clip plays back the "raw" clip as it is imported in unity without any modifications. In theory it should be possible to query if the clip is used in any cue and then play it back with the settings of that cue, but if the clip is used in multiple cues this might be confusing usability-wise as well.
     
  24. netpost

    netpost

    Joined:
    May 6, 2018
    Posts:
    135
    Thank you for the quick reply.

    Since the speaker icon is the raw audio, I will do the quick and dirty leveling before importing the raw audio asset folder. This is not a problem for me now that I understand that this is the way it was decided by design . But I can't select which audio clip to hear within the same cue with the audition button. For exemple if I have 3 different gunshots and want to fine tune the level between each, how do I select and hear them individually? all I can do is audition them randomly or use the speaker to the left of the clip and this only plays the raw sound without leveling.
     
  25. netpost

    netpost

    Joined:
    May 6, 2018
    Posts:
    135
    Is there a way to do this or not?

    Thank you.
     
  26. PWPeter

    PWPeter

    Joined:
    Dec 16, 2018
    Posts:
    383
    Sorry, I missed your reply earlier. You are right, for this case there is currently no way to audition a specific sound from a cue with multiple clips and I can see how this can be problematic. I will add this to our development backlog for Sectr, either we could make it so that the speaker button in the clip list always plays back that certain clip with the Audio Cue settings. (and if someone wants to listen to the raw sound they could go via the clip search in the bottom part of the window)
    Or we could add a second button, keep the speaker and have a small "Audition" button for each clip.
     
  27. netpost

    netpost

    Joined:
    May 6, 2018
    Posts:
    135
    Thanks for the quick reply.

    We could make it so that the speaker button in the clip list always plays back that certain clip with the Audio Cue settings

    That would be really great! But whatever is more convenient for you.
     
  28. AdamGoodrich

    AdamGoodrich

    Joined:
    Feb 12, 2013
    Posts:
    3,623
    Hey everyone,

    We are very pleased to announce the next iteration in the life of the SECTR suite with the release of SECTR COMPLETE 2019.

    After observing the way in which SECTR was being sold and used, we have decided only to continue only with a SECTR COMPLETE package, and to deprecate the others. There were not enough sales of the other packages to warrant the overhead of keeping and supporting them as separate packages, however, they are still actively being supported as part of the new SECTR COMPLETE SUITE.

    We have invested considerable time and effort into upgrading, adding support for the changes imposed by changes in the engine, and in particular have focused on improving and expanding on streaming and large world support, as this fits perfectly with our world creation suite of products.

    The biggest new features and enhancements in the latest version include:
    • Unity 2018.3 and Unity 2019.x support
    • Floating Point Origin Support (extra large world support)
    • Orders of magnitude improvements in the speed of the sectorization process
    • Seamless integration with Gaia, GeNa 2 and CTS (end to end integrated world building)
    • Many easy of use enhancements
    • Many documentation enhancement (including a terrain streaming guide).
    For a more detailed description of all the enhancements we have made please check out the release notes on the asset itself.

    In line with our commitment to continue to develop and our ongoing support the SECTR suite of products we will be charging a nominal upgrade fee. This fee is not being taken out of the business, it is ALL being invested back into growing the Procedural Worlds team, and pays for our development support resources.

    Upgrade pricing is:
    • SECTR Core -> SECTR COMPLETE 2019 $47
    • SECTR Audio -> SECTR COMPLETE 2019 $17
    • SECTR VIS -> SECTR COMPLETE 2019 $17
    • SECTR STREAM -> SECTR COMPLETE 2019 $17
    • SECTR COMPLETE -> SECTR COMPLETE 2019 $17
    And for anyone who purchased in the past 90 days, the upgrade is free.

    In addition to the enhancements we have made to the documentation we are also in the process of making a bunch of new video tutorials, and these will come online in the next few days and weeks.

    We hope that the community sees the upgrades we are making and change in direction to be the positive thing it is for the future of the SECTR Suite of products.

    This forum will no longer be actively monitored - for updates please head over to the SECTR COMPLETE forum.

    Cheers,
    Adam.
     
  29. brinca

    brinca

    Joined:
    Mar 29, 2015
    Posts:
    13
    Hi,

    I bought SECTR Complete a few months ago and I'm using SECTR Audio on a 2019.1 project right now, but am baffled with a strange issue, where the SECTR_AudioSystem component simply vanishes from prefabs (nested or not) erratically, without user intervention (sometimes it's there, but then suddenly it's gone, and I have to re-attach and reconfigure it all over again).

    This seems to work well if attached to regular hierarchy objects, it only seems to affect prefabs specifically.

    I've looked at the code but there doesn't seem to be anything in particular that might be causing this issue, maybe you have a better idea?
     
  30. PWPeter

    PWPeter

    Joined:
    Dec 16, 2018
    Posts:
    383
    I tried to reproduce your issue with the player prefab from the Sectr Audio demo scenes, but for me the Audio System on this prefab stays in place no matter what I do, do you have any pointers to when this happens? (e.g always on level load, when pausing the game, etc.) Could you please please check if you run the "AudioEnvironments" demo scene, to see if the Audio System on the player disappears there as well?
    You could also take the player from this scene from the SECTR\Demos\Audio\Prefabs folder, to see if the Audio System on it disappears as well over time if you just let it sit in your scene while running it.
    I also looked a bit around in the code and checked mentions for the SECTR_AudioSystem class, but did not find any place where it would explicitly remove one - doing this without a reproducible case is difficult though, since there could be a lot of different ways how this is handled in the code without actually mentioning the class names in proximity.
     
  31. brinca

    brinca

    Joined:
    Mar 29, 2015
    Posts:
    13
    Well, this happens in the Editor, not at runtime, and it seems to happen when there's a general recompile, though I'm not 100% sure... :p

    I've sort of fixed the issue through an ugly hack (I instantiate an Audio System manually at run time if none is found), which is good enough for now (though probably not for production).

    When I have some time I'll do some further testing on my own, in order to try to find a way to replicate the issue, and eventually get back to you, perhaps with a sample project and detailed repro steps.
     
    PWPeter likes this.
  32. PWPeter

    PWPeter

    Joined:
    Dec 16, 2018
    Posts:
    383
    A reproducible case would be really great, otherwise it is very difficult for me to do anything, I tried to make a few artificial code changes to trigger a recompile, but that did not do / delete anything yet.
     
  33. brinca

    brinca

    Joined:
    Mar 29, 2015
    Posts:
    13
    Oh ok, I think I get why this is happening... it's just the Singleton being enforced on enable (it destroys the game object if there is already an existing instance of the audio system).

    The problem is that this is a multiplayer FPS game with an unorthodox setup, as I have multiple cameras (one for each player), so that the player can switch characters with another player at any time (they don't simply teleport, they *become* the other player).

    I was setting up multiple audio systems, one for each camera, and enabling/disabling them as the player teleports from one character to another.
    When this problem started to occur, I tried with a single camera/audio system prefab, which would then reparented to the active player whenever a switch occurred.
    But for some reason this approach also makes the audio system component attached to the prefab disappear (in uncertain circumstances).

    As I said, I'll research this further when I have more time, but in the meantime, is there a way to set the audio system to a different audio listener programmatically? (the Listener accessor is currently read only)

    If so, this would allow me to have a single audio system for all characters, and then re-set the Listener to the appropriate player camera when another character becomes active.
     
  34. PWPeter

    PWPeter

    Joined:
    Dec 16, 2018
    Posts:
    383
    Sorry for the delayed reply, it was a while since I looked at the AudioSystem class so I could not answer from the top of my head without reviewing it again. I found that the "Listener" in the AudioSystem class is not a full Unity AudioListener object, but only a transform that is used for positioning calculations. Regularly the get accessor for it will return the transform of the AudioSystem, but I think it should be possible to call a function here instead by modifying the sectr source that will return the appropiate player camera instead, and you should be good.
     
  35. brinca

    brinca

    Joined:
    Mar 29, 2015
    Posts:
    13
    Yeah, I inspected the code earlier and it seems that the listener is mostly being used to track the location of the listening source (the player), so I modified the source slightly to include set functionality to the Listener accessor:

    Code (CSharp):
    1. public static Transform Listener
    2.     {
    3.         get
    4.         {
    5.             // ... (Editor specific includes) ...
    6.             return _Listener != null? _Listener : audioSystem.transform;
    7.         }
    8.  
    9.         set{
    10.             _Listener = value;
    11.         }
    12.     }
    13.     public static Transform _Listener;
    ...and this seems to be doing the trick just nicely! ;)

    I'm still going to research this deeper, when I have some free time, in order to find out why the component was being discarded from prefabs, as I don't like to leave loose ends... I'll let you know here when/if I find anything worthwhile.
     
    PWPeter likes this.
  36. brinca

    brinca

    Joined:
    Mar 29, 2015
    Posts:
    13
    Ok, so I know when and why the Audio System keeps disappearing mysteriously, and how to fix it (sort of)... ;)

    The problem is, as suspected, that the singleton pattern is being enforced on enable by destroying the component if there's already an instance of the Audio System in the scene.
    This becomes a problem with the new prefab workflow tools, because when you go into the prefab editor to edit a prefab, it creates a sandboxed "copy" of the prefab, but the scene is still loaded in the background, thereby violating the singleton principle.
    The sandboxed prefab version gets stripped of the Audio System component, and if you make any changes, they get saved automatically, thereby making the component disappear in the main scene as well (if it's within the prefab that you edited).
    Since only the sandboxed version is affected, if you don't make any changes in prefab mode, it is discarded when you go back into the main scene, keeping the Audio System intact.

    Repro steps:
    1. Create a game object with an Audio System component attached to it
    2. Drag it into the project folder in order to create a prefab
    3. Edit the prefab in the hierarchy (by clicking the little arrow to the right of it)
    4. Notice that the Audio System component is gone
    5. Make any change to the prefab in order to trigger a save
    6. Go back into the main scene and notice that the Audio System is also missing from the main scene

    So, the ugly workaround I came up with is simply to not destroy the component on enable, and issue a warning instead:

    Code (CSharp):
    1. // AudioSystem is a singleton, so there can only ever be one.
    2.         if(audioSystem && audioSystem != this)
    3.         {
    4. #if UNITY_EDITOR
    5.             if(Application.isEditor && !Application.isPlaying)
    6.             {
    7.                 Debug.LogWarning("More than one Audio System is not allowed");
    8.                 // GameObject.DestroyImmediate(this);
    9.             }
    10.             else
    11. #endif
    12.             {
    13.                 GameObject.Destroy(this);
    14.             }
    15.         }
    It's ugly, but it does the trick for now... I'll later research if there's a way to tell if we're in prefab mode and do a selective destroy based on that, but for now this solves the issue at hand :)
     
  37. PWPeter

    PWPeter

    Joined:
    Dec 16, 2018
    Posts:
    383
    Hi, thank you so much for reporting back, with your repro instructions I was finally able to reproduce the issue. As you already have pointed out, it is caused by the code not differentiating between the prefab edit stage and the regular scene, so the prefab that is being edited is being handled as a duplicate and gets the Audio System removed. The following prevents the issue for me:


    Code (CSharp):
    1.         // AudioSystem is a singleton, so there can only ever be one.
    2.         if(audioSystem && audioSystem != this)
    3.         {
    4. #if UNITY_EDITOR
    5.             if(Application.isEditor && !Application.isPlaying)
    6.             {
    7.                 if(PrefabStageUtility.GetCurrentPrefabStage()==null)
    8.                     GameObject.DestroyImmediate(this);
    9.             }
    10.             else
    11. #endif
    12.             {
    13.                 GameObject.Destroy(this);
    14.             }
    15.         }
    (You need to add "using UnityEditor.Experimental.SceneManagement;" for this to work, but from your past posts I think you would probably figured that one out immediately ;))
    Could you please review this fix from your side and give me the thumbs up if it is working for you? I'm in the process to assemble a smaller SECTR update with fixes from past support cases, so I could add this right in before it gets released if it is working well for you.
     
  38. brinca

    brinca

    Joined:
    Mar 29, 2015
    Posts:
    13
    Thumbs up, it's working!

    The only thing that I would add is to log a warning message when the component is forcibly removed, so that the user knows what is happening (having one would have avoided this confusion in the first place).

    In my case it was this:
    Code (CSharp):
    1. if(PrefabStageUtility.GetCurrentPrefabStage() == null){
    2.     Debug.LogWarning("More than one Audio System is not allowed, removing extra system");
    3.     GameObject.DestroyImmediate(this);
    4. }
     
    PWPeter likes this.
  39. PWPeter

    PWPeter

    Joined:
    Dec 16, 2018
    Posts:
    383
    Hi thanks for reporting back and for the suggestion, excellent idea, I will add this right in for the update.
     
    brinca likes this.