Quantcast
Channel: Photon Voice — Photon Engine
Viewing all articles
Browse latest Browse all 671

"get_devices is not allowed to be called from a MonoBehaviour"

$
0
0
Hi,

When I try to instantiate a prefab with PunVoiceRecorder (and it's two required components: PhotonVoiceSpeaker and AudioSource, plus a PhotonView), I get the error below:

get_devices is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'PhotonVoiceNetwork' on game object 'New Game Object'.

The problem appears to be that PhotonVoiceNetworkSingleton/PhotonVoiceNetwork constructor calls Microphone.devices.Length (devices is a property), and that doesn't seem to be allowed by Unity.
PhotonVoiceNetwork()
{
client = new UnityVoiceClient(this);
client.loadBalancingPeer.DebugOut = DebugLevel.ALL;
//PhotonNetwork.logLevel = PhotonLogLevel.Full;

if (Microphone.devices.Length < 1)
{
Debug.LogError("PUNVoice: No microphone device found");
}

// debug only
// client.UseLossCompensation = false;

// client.loadBalancingPeer.QuickResendAttempts = 3;
// client.loadBalancingPeer.SentCountAllowance = 7;
// PhotonNetwork.networkingPeer.QuickResendAttempts = 3;
// PhotonNetwork.networkingPeer.SentCountAllowance = 7;

//client.loadBalancingPeer.DebugOut = PhotonVoiceSettings.Instance.DebugLevel; // null ref while PhotonVoiceSettings is object's script
}
(Unity 5.4)

Any ideas?

Thank you!

Viewing all articles
Browse latest Browse all 671

Trending Articles