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

sosh
sosh
edited June 2016 in Photon Voice
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!

Answers

  • Since the Microphone.devices.Length isn't doing much other than logging an error if 0, I removed this section of code.
  • 2 weeks and no one has answered this question. I also commented this out but would be nice to get some kind of an official response to this.
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited August 2016
    Hi @Karel,

    I apologize about the delay. Sometimes we miss some discussions on the forum. If we take more than 2 days to answer you can ping us via email.

    Thank you for reporting this. The workaround suggested by @sosh does the job but rest assured a new version will be available soon with fixes and updates.

    Thank you for choosing Photon!