Placeholder-Software / Dissonance

Unity Voice Chat Asset
71 stars 5 forks source link

Disconnecting Client #4

Closed citron4000 closed 7 years ago

citron4000 commented 7 years ago

Hello,

I am using Dissonance for a VR project and will use the Oculus Audio Spatializer. So I want to have the PlaybackPrefab at the right place in space after the player is spawned, I place the PlaybackPrefab under the remote clients camera. I think this is a better way than to use Dissonance Audio Positioning.

When one of the client disconnect, the remote client is destroyed along with the PlaybackPrefab which is a child of the player. Then I get an error:

disconnect

It might not be a bug per say but maybe adding a few check to see if the Playback prefab is null is possible.. what do you think?

Thanks!

martindevans commented 7 years ago

I want to have the PlaybackPrefab at the right place in space after the player is spawned

Dissonance position tracking does do this for you. It creates an invisible game object at the correct position and attaches the playback prefab to it. I haven't tested this with the Oculus Audio Spatializer specifically but it should just work(tm). The general idea is that you don't need to worry about the playback prefab at all - as long as you attach the DissonancePlayer components to the right entity all the audio will be synchronised in the correct position.

I have a few more questions about this error:

untitled

untitled

citron4000 commented 7 years ago

Thanks for the reply.

You are right the Audio Spatializer from Oculus would work on the PlayerPrefab without problem using Dissonance positional audio (it works with any AudioSource). However, even though the gain in bandwidth might be insignificant, putting the PlaybackPrefab under the player allows us to save the positional audio data send from Dissonance since we are syncing the player anyway. We are also planning to move the PlaybackPrefab in other positions on our own depending on the player's action so that is why we would prefer to manage this part ourselves.

About your questions:

error1 error2

  1. When the remote player connects do you have a "Player {id} voice comms" object created (automatically) as a child of whichever game object has the "Dissonance Comms" component attached?

Yes we do have this object in the first place when a client connects.

  1. If you do have the voice comms component that means you have two playback prefabs (the one you created manually, and the one Dissonance created automatically). Can you confirm which one the remote voice is coming from? To do this select the game object and inspect the "Sample Playback Component", when you speak it's VU meter will wobble around if it's playing audio.

I actually do not create a PlaybackPrefab myself, I let Dissonance do it and then I manually add it (with a script) under the remote player when it has connected.

Thanks again

TomGillen commented 7 years ago

Dissonance already handles the situation you describe. Rather than move the PlaybackPrefab under your remote player entities, you should instead attach a DissonancePlayer script to each remote player entity and set the PlayerId to that of the relevant player. Dissonance will then mirror the position of this entity for you.

If you are using the Unity HLAPI for networking, you can use HlapiPlayer instead, which will wire the player ID automatically.

Currently, we do not send player position over the network ourselves. We rely on the user having an entity for each remote player in their scene and keeping its position in sync themselves, under the assumption that the game is probably already doing this.

citron4000 commented 7 years ago

Okay, that sounds good, thanks for your time on this, I'll change it on our side.

citron4000 commented 7 years ago

So the positional tracking works well and moves with the player. However, I think it is fairly common in VR games to first spawn a first Player then spawn a separate object for the head and and then objects for the two hands and give it client authority. In this case, if we only attach the PlaybackPrefab to the Player (and not the head), we don't have the rotation and position of the head which might be important for some audio spatialiser. Of course the base Player could reflect the head tracking but I think that wouldn't be a very elegant solution.

What is your thoughts on that? Would it be possible to attach the PlaybackPrefab to other objects besides the Player?

martindevans commented 7 years ago

Ultimately Dissonance just needs a component which implements the IDissonancePlayer interface passed into DissonanceComms:StartTracking. The HlapiPlayer class (which implements this interface for you) relies on the NetworkBehaviour.isLocalPlayer and returns the transform of whatever it is attached to. I guess this won't work because the body is the local player, but you want the transform from some other object (i.e. the head).

I think you're going to need to write your own IDissonancePlayer implementation (this is pretty simple, you can probably start by copying HlapiPlayer and adapting it to your needs). The two ways it sounds like you could do this:

Unfortunately we don't have any decent documentation on this (that's a serious oversight I'll be fixing today). So feel free to ask if you need help implementing that :)

martindevans commented 7 years ago

I have written some additional documentation to do with IDissonancePlayer: https://dissonance.readthedocs.io/en/latest/Tutorials/Custom-Position-Tracking/.

If you're still having problems I suggest opening another issue :)

TomGillen commented 7 years ago

If your player head is part of the player prefab that unity is instantiating for each local and remote player, then you should be able to move it onto the head.

This is assuming that Unity marks children of the player as also being local to the player, which is not something I've tested.

citron4000 commented 7 years ago

Many thanks for your help.