Placeholder-Software / Dissonance

Unity Voice Chat Asset
71 stars 5 forks source link

[help] Where should I set LocalPlayerName? #65

Closed jakemoves closed 6 years ago

jakemoves commented 6 years ago

Context

I'm trying to set LocalPlayerName so clients can set a handle (name).

Expected Behavior

I'd expect to be able to assign this variable a value.

Actual Behavior

When I do this in a script in my scene with code like:

comms = GameObject.Find("DissonanceSetup").GetComponent<DissonanceComms>();
comms.LocalPlayerName = "testPlayerName"; 

I get the error:

DissonanceException: [Dissonance:Core] DissonanceComms: Error: Cannot set player name when the component has been started! This is likely caused by "directly setting the 'LocalPlayerName' property too late", see the documentation at "https://placeholder-software.co.uk/dissonance/docs/Reference/Components/Dissonance-Comms.md" or visit the community at "http://placeholder-software.co.uk/dissonance/community" to get help. Error ID: 58973EDF-42B5-4FF1-BE01-FFF28300A97E
Dissonance.DissonanceComms.set_LocalPlayerName (System.String value) (at Assets/Plugins/Dissonance/DissonanceComms.cs:93)
UIManager.Start () (at Assets/Scripts/UIManager.cs:53)

The documentation links are out of date, and it's not clear to me when I can set the PlayerName and how.

Your Environment

martindevans commented 6 years ago

That documentation link was misformatted, it should have the .md at the end, sorry about that. Here's the correct link: https://placeholder-software.co.uk/dissonance/docs/Reference/Components/Dissonance-Comms. However that still doesn't directly answer your question!

As the error message says, you can't change the player name once the DissonanceComms component has been started (i.e. the Unity MonoBehaviour.Start method has been called). So if you really want to set this to a custom value you'd need to have it in the scene but disabled, set the LocalPlayerName property and then enable it.

DissonanceComms comms; //In scene, but not enabled
comms.LocalPlayerName = "A Name";
comms.enabled = true;

However this isn't ideal because the player can't changed their name without leaving the session, destroying the DissonanceComms components, creating entirely new ones and then rejoining the session. To be honest I think this is a poorly named property - rather than considering this a human readable name you should think of it as an ID used by Dissonance. Then you can layer your own names on top of this (and Dissonance continues to use it's default IDs internally).

I'll close this issue since I've answered the question, but feel free to ask followup questions if it's not clear :)

jakemoves commented 6 years ago

Thank you! Yes, it wasn’t really clear that it was a basically immutable ID. So there are definitely better ways to do what I’m trying to do :)

On Nov 13, 2017, at 9:19 AM, Martin Evans notifications@github.com wrote:

That documentation link was misformatted, it should have the .md at the end, sorry about that. Here's the correct link: https://placeholder-software.co.uk/dissonance/docs/Reference/Components/Dissonance-Comms. However that still doesn't directly answer your question!

As the error message says, you can't change the player name once the DissonanceComms component has been started (i.e. the Unity MonoBehaviour.Start method has been called). So if you really want to set this to a custom value you'd need to have it in the scene but disabled, set the LocalPlayerName property and then enable it.

DissonanceComms comms; //In scene, but not enabled comms.LocalPlayerName = "A Name"; comms.enabled = true; However this isn't ideal because the player can't changed their name without leaving the session, destroying the DissonanceComms components, creating entirely new ones and then rejoining the session. To be honest I think this is a poorly named property - rather than considering this a human readable name you should think of it as an ID used by Dissonance. Then you can layer your own names on top of this (and Dissonance continues to use it's default IDs internally).

I'll close this issue since I've answered the question, but feel free to ask followup questions if it's not clear :)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.