This happens when the shotgun pellets in my game (there are 30+ pellets in a shot) hit the wall; each one creates an object that contains an audiosource. Is there a limit to the number of audioSource’s that can exist in a scene? I’ve stopped the message for now by removing a redundant audiosource (which would have brought the total to approximately 100 sources at the moment of impact). I am, however, concerned that when the action heats up and lots of bullets are flying around, I might hit this limit again.
though i can’t speak as to the Unity error - if i understand what you are doing i think maybe instantiating 30 objects which then instantiate 30 sound files is not the best way to simulate a shotgun - accurate maybe but slow. most bullet firing weapons are done with raycast instead of an actual projectile (as in the fps tut).
i’m not sure how to replicate the spread over distance, but at the very least i think you should instantiate just one sound file at the hit point that sounds like 30 pellets hitting an object.
Yes, in fact the first iteration of my gun code did do this. I found the “create a bullet” approach produces a much more pleasing result visually, and the bullets in and of themselves don’t hurt the framerate in the slightest. If you reuse the bullet object for different weapons, a lot of code is greatly simplified as well. (I’m using it for the handgun, automatic rifle, and shotgun, with slightly different properties on each) There’s also another aspect to this which I’m going to hold on to until I release some sort of playable version of my game…
Right now the shotgun uses the same bullet object as every other gun, though I’m considering giving it its own pellet object for just this reason.
I too am curious what might cause “AL_INVALID_OPERATION”–our game does that too. It seems harmless–everything still works including the sounds–but I don’t like to leave a warning unattended!
i’m intrigued.
i’m working on an fps myself - haven’t gotten to the shotgun though ; )
i can see how having multiple pellets would give you nicely accurate spread hit locations, but nevertheless it still seems to me one sound instance would be best - especially once you’ve got the rest of the scene with SFX as well. do you notice a frame hit when they all go off or is it just the error message?
Well, I’m not actually working on an FPS - it’s a top-down action game akin to Metal Gear Solid. A lot of the concepts end up being about the same, though.
Yeah, I’m going to have to figure out some way to not create all those audio sources. There is a slight frame hit if all the pellets hit the same surface (e.g. on the same frame); I’m assuming that’s because all 30+ sounds are loaded and started at the same time.
Graphically, there’s basically no performance hit for having lots of pellets.
In case anyone is wondering about the physical bullet objects - I create them, give them a speed (about 200) and point them towards the target in the weapon’s shoot script; in a script attached to the bullet object, I:
Cast a ray along the movement vector with distance of speed*Time.deltaTime
Scale the z component of the transform (forward) to speed*deltaTime/2, creating the nice bullet trail
Set the material to a semitransparent orange
Translate the object by speed*Time.deltaTime
The first step here is the critical one: at such high speeds, you really can’t rely on standard collision detection much. If that ray hits, you would destroy the bullet and perform whatever actions a normal “bullet raycast” would take, like creating sparks.
I’m also getting this error - and I only have one sound in the scene! It only started showing up for me recently as well, although I think it appeared in 1.5.0 first. The file is an OGG if that has any bearing.
I simulate many many shotgun bullets in my 3DU entry by shooting about 8 bullets that each show about 10 bullet particles in an area and get collisions with Physics.OverlapSphere. I don’t use mesh colliders in my game though so that might not work for you.
I have sinned and used volume values way over 1 without getting this error, and now that I have few (if any) that are incorrect I have triggered this error once. Is there anything to look at besides editor volume values?
I’m also getting this error and all i’m doing is calling
audio.PlayOneShot(Thirty);
I can call this in a Start() or Awake() function and it works fine. But if I create my own function I get what sounds like metallic sounds (like cylons from the old 70’s Battlestar Galactica) and then I get the error.