Search code examples
parse-platformunity-game-enginepubnub

Parse & PubNub in Unity


I am having the problem that Parse and PubNub SDK cannot work in the same project.

The problem I have is both SDKs seems to have System.Threading in their DLL file. So I will get the following error

error CS0433: The imported type System.Threading.Tasks.Task1' is defined multiple times

I use the latest Parse Unity SDK and PubNub example project here https://github.com/pubnub/c-sharp/tree/master/unity

Anyone has the same issue and how could you resolve it?


Solution

  • Parse has their own "Task" class which clashes with the "Task" class in System.Threading.dll.

    There are 2 ways to resolve the issue:

    • You can either use the beta version of PubNub's Unity SDK from here (link to beta is in the read me). This version removes the dependency on System.Threading.dll.

    • Or use var saveTask = gameScore.SaveAsync (); instead of: Task saveTask = gameScore.SaveAsync (); in the version you are using.

    Another Example:

    using UnityEngine;
    using System.Collections;
    using Parse;
    using System.Threading;
    using System.Collections.Generic;
    using System;
    using PubNubMessaging.Core;
    using System.Threading.Tasks;
    public class NewBehaviourScript : MonoBehaviour {
        public void OnGUI (){
            SignUpNewUser ();
        }
        public void SignUpNewUser (){
            var returnTask = ParseUser.LogInAsync  ( login, password    ).ContinueWith (t => {
                return ParseUser.Query.FindAsync ();
            });
            returnTask.Unwrap();
        }
    }