Hey there,
I have server authoratative actions in my shooting game like “successfully hit” sound effect etc
Im starting to toy with audio and playing sounds so I might be going about this the completely wrong way.
I am currently using
What is the recommended method to get an audio clip to play on all machines at the location?
Do I just write a simple prefab prefab with an audio clip and network object and spawn it or is there a better way to “make an audio clip play at location for all clients”?, heck, is there a built in method on a network behaviour or something?
Hi there,
If you want to destroy NetworkObject you should use “.Despawn()” method because this method triggers on all players.
You mentioned above, you can use “clientRPCs” or listen to “OnNetworkSpawn” method then play the audio.
If something dies, that state change has already been communicated over the network. Whatever that thing is, when it responds to its death it plays a sound fx indiscriminately, meaning it shouldn‘t check if it‘s the owner or a local instance or whatever. It just play the audio and other things (vfx, animation) when it dies.
Hi @Tsunamisukoto , all you need to do is to call a ClientRPC from the server. You don’t need to pass the AudioClip to it as you can retrieve it locally (I.E: assign it in the inspector), just the position.
Hi Riku, i am having the same problem audiosource is a non nullable value so it does not serialize it and i cant play it on server rpc, how exactly can i play the audio source
Your code should never play sounds on a server. Servers are for handling logic. Always assume a server has no local player, or you’ll have serious issues when implementing server-authoritative models proeprly.
You need to change the logic of your code so that the clip is played on client, I.E: through a ClientRPC