Bug Report: PUN2 Voice Prefab not working without Auto Create Recorder

I wasn't able to transmit voice from my voice prefab until I enabled "Auto Create Recorder" in "Photon Voice View". Before that, I had manually added a "Recorder" component to my prefab, configured it (including setting the "Transmit" attribute to true) and dragged it into the "Photon Voice View: Recorder In Use" field.

Nevertheless, I was getting a null exception (couldn't find the Recorder). After removing the Recorder and enabling "Auto Create Recorder", it started working.

I have "Use Primary Recorder" disabled, and no Primary Recorder in "Photon Voice Network", either.

I'm on Unity 2018.2.11f1, PUN2 and Photon Voice 2.

Not sure if I was doing something wrong or if it's a bug, thought I'd report it here so that you can take a look at it.


  • JohnTube
    JohnTube mod
    edited November 2018
    Hi @shafy,

    Thank you for choosing Photon and for your bug report!

    I have managed to reproduce the issue described yes.
    The Recorder is being accessed from the PhotonVoiceView.OnEnable before Recorder.Awake is called which throws a null reference exception when trying to access Logger property which is not initialized yet.
    This can be fixed in multiple ways:

    1. Always put Recorder component before PhotonVoiceView in the same GameObject so its Recorder.Awake is called before any PhotonVoiceView methods
    2. Make the Recorder.Logger (VoiceComponent.Logger) property getter lazy initialize a backing field to avoid null reference:
    public abstract class VoiceComponent : MonoBehaviour, ILoggable
            private VoiceLogger logger;
            public VoiceLogger Logger
                    if (logger == null)
                        logger = new VoiceLogger(this, string.Format("{0}.{1}", name, this.GetType().Name), logLevel);
                    return logger;
                protected set { logger = value; }
            protected virtual void Awake()
                if (logger == null)
                    logger = new VoiceLogger(this, string.Format("{0}.{1}", name, this.GetType().Name), logLevel);
    I don't know how bad is this considering the additional null check each time Logger is accessed.
    3. Delay accessing anything Recorder related until Recorder.Awake is called. I think this is commonly used but I don't know if it's a good idea to do it here.

    We will fix this in the next update.
    You could try any of the aforementioned solutions (1 or 2) for now.
  • Thanks for confirming and clarifying, @JohnTube :-)
  • shafy
    edited November 2018
    Just tested it with putting Recorder before PhotonVoiceView, and now I get this bug here:

    ArgumentException: Couldn't acquire device ID for device name ,[H
    11-02 10:25:17.596 19965 19981 E Unity : at Photon.Voice.Unity.MicWrapper..ctor (System.String device, Int32 suggestedFrequency) [0x00075] in /Users/can/Unity/multiplayer test/Assets/Photon/PhotonVoice/PhotonVoiceApi/Platforms/Unity/MicWrapper.cs:31
  • Hi @shafy,

    This is something new.
    Does this happen in the Unity Editor or on a build?
    What is the target platform?
    What Unity version do you use?
    Could you try switching Microphone Type to Photon instead of Unity?
    Or if you have more than one Unity device try different ones.
  • Hey @JohnTube

    It happens when running on the device (Oculus Go). I have 2018.2.11f1.

    It works when I change the Microphon Type to Photon! Is this the recommended setting?
  • Hi @shafy,

    I wouldn't say recommended but it's an alternative to Unity microphone API as we noticed it's sometimes unreliable/limited and has issues between versions or on some platforms. It's definitely a workaround if Unity microphone does not work.

    Could you try this version here.
    Please be careful when importing: Unity Editor "Native Library Updates".
    I recommend testing in a clean/fresh/new/empty project.