1
\$\begingroup\$

I am trying to allow the user to share the final game score on their FaceBook timeline. I am following FaceBook tutorial and examples. When I try to download and import the FaceBook SDK package (7.11-2.0) in Unity (2017.3) I get the error:

error CD1704: An assembly with the same name 'FaceBook.Unity.Settings' has already been imported. Consider removing one of the references or sign the assembly Library/FacebookSDK/FaceBook.Unity.Settings.dll (Location of the symbol related to previous error)

I read on other posts that the latest version of Unity may have the Facebook SDK already integrated, and will not require importing the package manually.

I therefore removed the from my project. The error disappear, but when I try to initialize the Facebook SDK for Unity using the code below, I get the error:

The name `FB' does not exist in the current context

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Facebook.Unity;

public class ShareOnFaceBook : MonoBehaviour {

    // Use this for initialization
    void Awake () {

    if (!FB.IsInitialized) {
        // Initialize the Facebook SDK
        FB.Init(InitCallback, OnHideUnity);
    } else {
        // Already initialized, signal an app activation App Event
        FB.ActivateApp();
    }
}
\$\endgroup\$
1
\$\begingroup\$

Assuming you are following this: https://developers.facebook.com/docs/unity/examples

Unity 2017.1.0f3 without the Facebook SDK installed leads to this error:

Error CS0246: The type or namespace name 'Facebook' could not be found (are you missing a using directive or an assembly reference?) (CS0246) (Assembly-CSharp)

Once Facebook SDK is installed, the script works (as long as you include all of the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Facebook.Unity;

public class ShareOnFaceBook : MonoBehaviour {

    // Use this for initialization
    void Awake () {

        if (!FB.IsInitialized) {
            // Initialize the Facebook SDK
            FB.Init(InitCallback, OnHideUnity);
        } else {
            // Already initialized, signal an app activation App Event
            FB.ActivateApp();
        }
}private void InitCallback ()
{
    if (FB.IsInitialized) {
        // Signal an app activation App Event
        FB.ActivateApp();
        // Continue with Facebook SDK
        // ...
    } else {
        Debug.Log("Failed to Initialize the Facebook SDK");
    }
}

private void OnHideUnity (bool isGameShown)
{
    if (!isGameShown) {
        // Pause the game - we will need to hide
        Time.timeScale = 0;
    } else {
        // Resume the game - we're getting focus again
        Time.timeScale = 1;
        }
    }
}

I can't find proof that FB SDK is included with newer Unity versions. Perhaps it is offered in the installer.

I speculate that your Unity or C# environment (MonoDevelop) is bugging out and might be "fixed" by a restart. Alternatively it could be that you only partially removed the FB SDK or have various versions of it conflicting with itself.

Also: perhaps your "FB"-related error refers to another script.

To verify, start a new project, import the FB SDK .unitypackage and try out above C# script. It should work.

\$\endgroup\$
  • \$\begingroup\$ Thank you for your time. To answer your comments, yes, that is indeed the documentation page I was following. I tried to reboot Unity and MonoDevelop and that unfortunately did not fix the issue. Your are right when you say FB-SDK is not part of Unity installation. As a matter of fact, when I try to build the project I get the Error CS0246. However, Monodevelop build just fine and the project can run in the editor. So clearly Monodevelop is still recognizing the namespace. If I try to import the FB-SDK package, I get the Error CS1704 I mentioned. This is also happening in a brand new project. \$\endgroup\$ – Alex Feb 5 '18 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.