Forum Multiplayer Can't connect to PlayerIO in Unity

Discussion and help relating to the PlayerIO Multiplayer API.

Can't connect to PlayerIO in Unity

Postby Kikikan » May 18th, 2017, 5:23 pm

Hey,

(Sorry if it's the wrong forum)

I wanted to use Player.IO's help in my game, and it seems to give me an error when I try to execute this piece of code:
Code: Select all
public void ConnectToPlayerIO ()
    {
        username = usernameInput.text;
        arguments.Add("username", username);
        PlayerIO.Authenticate("[my-game-id]", "public", arguments, null, (Client cli) =>
        {
            Debug.Log("SUCCESSFULLY CONNECTED");
        });
    }


The error message is this:
System.NullReferenceException: Object reference not set to an instance of an object
at PlayerIOClient.PlayerIO+ChannelMonitor+<>c__DisplayClass21`3[PlayerIOClient.Internal.identifier115+identifier144,PlayerIOClient.Internal.identifier115+identifier152,PlayerIOClient.PlayerIOError].<Call>b__20 (PlayerIOClient.PlayerIOError e) [0x00000] in <filename unknown>:0
at PlayerIOClient.Internal.identifier115+identifier815+identifier817[PlayerIOClient.Internal.identifier115+identifier144,PlayerIOClient.Internal.identifier115+identifier152,PlayerIOClient.PlayerIOError].MoveNext () [0x00000] in <filename unknown>:0
UnityEngine.Debug:LogError(Object)
PlayerIOClient.Internal.identifier817:MoveNext()
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)


If I remove the "arguments" dictionary and try to authenticate without any authenticationArguments I get this error:
NullReferenceException: Object reference not set to an instance of an object
PlayerIOClient.PlayerIO+<>c__DisplayClass15.<Authenticate>b__10 ()
PlayerIOClient.PlayerIO.ensureInitialized (PlayerIOClient.Callback callback)
PlayerIOClient.PlayerIO.Authenticate (System.String gameId, System.String connectionId, System.Collections.Generic.Dictionary`2 authenticationArguments, System.String[] playerInsightSegments, PlayerIOClient.Callback`1 successCallback, PlayerIOClient.Callback`1 errorCallback)
PlayerIOClient.PlayerIO.Authenticate (System.String gameId, System.String connectionId, System.Collections.Generic.Dictionary`2 authenticationArguments, System.String[] playerInsightSegments, PlayerIOClient.Callback`1 successCallback)
MultiplayerManager.ConnectToPlayerIO () (at Assets/Scripts/MultiplayerManager.cs:35)
UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:154)
UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:637)
UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:773)
UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:52)
UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44)
UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update()



I'm using Unity 5.6.1f1, but the same error appeared in Unity 5.6.0f3.
Does anyone have an idea about what's going on and how can I run the code?

Thanks for the help in advance.
Kikikan
 
Posts: 3
Joined: August 6th, 2016, 10:38 pm

Re: Can't connect to PlayerIO in Unity

Postby Henrik » May 19th, 2017, 5:29 am

What type is 'arguments' in your code?

If you do SimpleUsers authentication, you need a password in there as well.

What happens if you do something like this:

Code: Select all
public void ConnectToPlayerIO () {
    username = usernameInput.text;
    PlayerIO.Authenticate("[my-game-id]",
        "public",
        new Dictionary<string, string>(){ { "username", username }, { "password", "[secret]" } },
        null,
        (Client cli) => {
            Debug.Log("SUCCESSFULLY CONNECTED");
        },
        (PlayerIOError error) => {
            Debug.Log(error);
        });
}
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm

Re: Can't connect to PlayerIO in Unity

Postby Kikikan » May 19th, 2017, 4:40 pm

Henrik wrote:What type is 'arguments' in your code?

If you do SimpleUsers authentication, you need a password in there as well.

What happens if you do something like this:

Code: Select all
public void ConnectToPlayerIO () {
    username = usernameInput.text;
    PlayerIO.Authenticate("[my-game-id]",
        "public",
        new Dictionary<string, string>(){ { "username", username }, { "password", "[secret]" } },
        null,
        (Client cli) => {
            Debug.Log("SUCCESSFULLY CONNECTED");
        },
        (PlayerIOError error) => {
            Debug.Log(error);
        });
}


Oh my god it worked! I didn't use SimpleUsers, just simply the basic authentication method, but then I switched to SimpleUsers and now it works with your code. Thank you very much! :D
(I should've read the authentication documentation :roll: )
Kikikan
 
Posts: 3
Joined: August 6th, 2016, 10:38 pm

Re: Can't connect to PlayerIO in Unity

Postby Henrik » May 19th, 2017, 8:28 pm

Glad it helped, but that's a super weird error message though, normally you should get a clear PlayerIOError back that tells you what went wrong and how to fix it. Maybe because you skipped the error callback in your code?
Henrik
.IO
 
Posts: 1880
Joined: January 4th, 2010, 1:53 pm


Return to Multiplayer