Home | Documentation | Atomic Chat | Github

3D Sound Problem



Hello all. What i doing wrong in this code ? All seems to be fine, but SoundSource3D wont working anyway…
Just “SoundSource”-component working fine, but 3D not.

    SoundSource3D source = Node.CreateComponent<SoundSource3D>();
    source.SetDistanceAttenuation(1f, 150f, 1f);


Hello, if you open the Chickens example from the example browser, does the 3D sound work there when you play it? The chicken prefabs has a 3D sound component :slight_smile:


For a C# example, the Racer2D example has a SoundSource3D created in Vehicle.cs, I tried both JS and CS on Linux, and they functioned properly. Is the Node the component is created on in the scene?


Yes, all work perfect. Even Racer2D is work fine. I dont really know what is the problem, but i used AtomicMutant example for this project. Might be something with this ?


Yes, Node component are created on scene. I’m trying to create a simple physical bullet, and on the end of the way on collision, destroyed “targeted node” must play the 3DSound, but it don’t.

Here is the code, if it necessary…

void SubscribeEvents()
    SubscribeToEvent<NodeCollisionEvent>(Node, HandleNodeCollision);

void Start()

void HandleNodeCollision(NodeCollisionEvent e)
    // Get the other colliding body, make sure it is moving (has nonzero mass)
    RigidBody otherBody = e.OtherBody;
    var cache = GetSubsystem<ResourceCache>();

    if (otherBody.Mass > 0.0f)
        Node soundNode = Scene.CreateChild("Sound");
        soundNode.Position = otherBody.Position;

        SoundSource3D source = e.OtherNode.CreateComponent<SoundSource3D>();
        source.Gain = 1;
        source.InnerAngle = 360;
        source.OuterAngle = 360;


        if (e.OtherNode.Name == "Target")


You appear to be removing the OtherNode which has the SoundSource3d attached to it. Playing the sound may take a little time to start, longer than a few c# statements. A simple test would be, not removing the OtherNode, and listen if the sound is played.


It’s not working. Even after deleting remove statements it continuous to not starting sound. I can transfer a whole project if you want see it your self.


There are two problems. The first is with the SoundListener. I added these lines to CharacterExample.cs around line 22

	Audio audioSystem = GetSubsystem<Audio>();
	audioSystem.SetMasterGain("Effect", 1.0f);  //doesnt really need this, its defaulted to 1.0f

And that allows your character to hear all that gunfire. There is a SoundListener attached to the scene CharacterExample node, that should have worked.
And the second problem is what I suspected, if you delete the node the sound is playing on, it doesn’t have time to play. And shouldn’t the sound come from the gun end not the bullet end ?


I can’t believe, it working. Damn dude, HUGE thanks to You :+1: