Unity 5 automaticlly making instantiated sounds 3d

So I ran into this problem where after i imported my game from Unity 4.6 to Untiy 5 there is that thing that you can only change sounds from 3d to 2d if they are permenantly put on an object, and when I instantiate a sound such as the crack sound, it automaticlly makes it 3d and doesnt let me change it to 2d in the sound file itself, I will be glad if anyone could help and give any suggestions. Thank you!

The 2D/3D setting is referred to as Spatial Blend now and is a property of the AudioSource, as such, you would need an instance of the object in order to change this property.

You could create your own PlayClipAtPoint function and then call then instead of AudioSource.PlayClipAtPoint, this would allow you to return the AudioSource as an instance and set the Spatial Blend property, along with any others you might want also, such as pitch etc.

I have set a AudioSource variable called Crack in the script and attached it in the editor and tried setting it’s spatial blend in the Start method by writing Crack.spatialblend but it doesnt auto complete the spatialblend as if it didnt exist at all.

1 Like

Never mind thanks for the suggestions but I’ve figured out the problem, when I set an Audio Variable i accidently set it as an AudioClip instead of an AudioSource which is what I should have done.

1 Like

No worries.

Just one thing to consider, if you are creating an AudioSource object within each Brick object, you could potentially have hundreds of them that never get used, e.g. if the player doesn’t clear all the bricks.

Using a static method to create a game object, add an AudioSource component, set the clip, position and volume, play the clip, and then destroy the game object after the clip duration - thus, duplicating the behaviour of PlayClipAtPoint would give you the opportunity to just spawn what you need, when you need it and still be able to set the spatial blend (and any properties).

Just something worth considering. :slight_smile: