Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Error in Unity2d Facebook SDK ArgumentException: Getting control 1's position in a group with only 1

Discussion in 'Editor & General Support' started by AlbertJNT, Aug 12, 2014.

  1. AlbertJNT

    AlbertJNT

    Joined:
    Aug 7, 2014
    Posts:
    5
    Well I try to do some game in Unity2D, and in this game I put the Facebook SDK, and when I try to share de punctuation of my game, I have two this error:

    • NullReferenceException: Object reference not set to an instance of an object
    • Getting control 1's position in a group with only 1 controls when doing Repaint
    And I don't know how to fix it.

    Anybody can help me ?

    My codi is this:

    Code (CSharp):
    1. using UnityEngine;
    2. using System;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using System.Linq;
    6. using Facebook.MiniJSON;
    7.  
    8. public sealed class facebookControl : MonoBehaviour {
    9.  
    10.     private bool isInit = false;
    11.  
    12.     private int highScore = 0;
    13.  
    14.     static facebookControl instance = null;
    15.    
    16.     public string FullName;
    17.     public string Gender;
    18.     public GUISkin MenuSkin;  
    19.  
    20.     public Rect LoginButtonRect; // Position of login button
    21.  
    22.     void Start()
    23.     {  
    24.         if (!FB.IsLoggedIn)                                                                                            
    25.         {                                                                                                              
    26.             CallFBLogin();
    27.         }  
    28.     }
    29.  
    30.     void Awake ()
    31.     {
    32.         if (instance == null)
    33.             instance = this;
    34.         enabled = false;                
    35.         CallFBInit(); //Inicializamos el SDK de Facebook
    36.  
    37.         //Cojemos la puntiacion mas alta
    38.         highScore = PlayerPrefs.GetInt("High Score", 0);
    39.  
    40.         DontDestroyOnLoad(gameObject);
    41.     }
    42.  
    43.     private void CallFBInit()
    44.     {
    45.         FB.Init(SetInit, OnHideUnity);
    46.     }
    47.  
    48.     private void SetInit()                                                                      
    49.     {                                                                                          
    50.         Debug.Log("SetInit");                                                                
    51.         enabled = true; // "enabled" is a property inherited from MonoBehaviour                
    52.         if (FB.IsLoggedIn)                                                                      
    53.         {                                                                                      
    54.             Debug.Log("Already logged in");                                                  
    55.             OnLoggedIn();                                                                      
    56.         }
    57.         isInit = true;
    58.     }
    59.    
    60.     private void OnHideUnity(bool isGameShown)
    61.     {
    62.         Debug.Log("Is game showing? " + isGameShown);
    63.     }
    64.  
    65.     public static facebookControl Instance ()
    66.     {
    67.         return instance;
    68.     }
    69.  
    70.     public string ApiQuery = "";
    71.     private string lastResponse = "";
    72.     private Texture2D lastResponseTexture;
    73.  
    74.     void OnGUI() {
    75.         //GUI.skin = MenuSkin;
    76.         //GUILayout.Box("", MenuSkin.GetStyle("box"));
    77.  
    78.         Debug.Log(FB.AppId);
    79.         Debug.Log(FB.UserId);
    80.  
    81.         GUI.enabled = isInit;
    82.     }
    83.  
    84.     #region FB.Login() example
    85.    
    86.     private void CallFBLogin()
    87.     {
    88.         FB.Login("email,publish_actions", LoginCallback);
    89.     }
    90.    
    91.     void LoginCallback(FBResult result)
    92.     {
    93.         if (result.Error != null)
    94.             lastResponse = "Error Response:\n" + result.Error;
    95.         else if (!FB.IsLoggedIn)
    96.         {
    97.             lastResponse = "Login cancelled by Player";
    98.         }
    99.         else
    100.         {
    101.             lastResponse = "Login was successful!";
    102.             FB.API("/me?fields=id,name", Facebook.HttpMethod.GET, APICallback);
    103.             sharePunctuation();
    104.         }
    105.         Debug.Log (lastResponse);
    106.     }
    107.  
    108.     void APICallback(FBResult result)
    109.     {
    110.         result_str = result.Text;
    111.         profile = Util.DeserializeJSONProfile(result.Text);
    112.     }
    113.  
    114.     private void CallFBLogout()
    115.     {
    116.         FB.Logout();
    117.     }
    118.     #endregion
    119.  
    120.     /*Sirve para compartir la puntuacion en Facebook*/
    121.     private void sharePunctuation()                                                                                                
    122.     {                                                                                                                          
    123.         Debug.Log("sharePunctuation");                                                                                          
    124.         FB.Feed(                                                                                                                
    125.                 linkCaption: "Acabo de hacer mi record " + highScore,              
    126.                 picture: "http://www.friendsmash.com/images/logo_large.jpg",                                                    
    127.                 linkName: "Mole miner",                                                                
    128.                 link: "http://apps.facebook.com/" + FB.AppId + "/?challenge_brag=" + (FB.IsLoggedIn ? FB.UserId : "guest")      
    129.                 );                                                                                                              
    130.     }
    131.    
    132.     void OnLoggedIn()                                                                        
    133.     {                                                                                        
    134.         Debug.Log("Logged in. ID: " + FB.UserId);                                          
    135.     }  
    136.  
    137.     void Callback(FBResult result)
    138.     {
    139.         lastResponseTexture = null;
    140.         // Some platforms return the empty string instead of null.
    141.         if (!String.IsNullOrEmpty(result.Error))
    142.             lastResponse = "Error Response:\n" + result.Error;
    143.         else if (!ApiQuery.Contains("/picture"))
    144.             lastResponse = "Success Response:\n" + result.Text;
    145.         else
    146.         {
    147.             lastResponseTexture = result.Texture;
    148.             lastResponse = "Success Response:\n";
    149.         }
    150.     }
    151.  
    152.     #region FB.AppRequest() Direct Request
    153.    
    154.     public string DirectRequestTitle = "";
    155.     public string DirectRequestMessage = "Herp";
    156.     private string DirectRequestTo = "";
    157.    
    158.     private void CallAppRequestAsDirectRequest()
    159.     {
    160.         if (DirectRequestTo == "")
    161.         {
    162.             throw new ArgumentException("\"To Comma Ids\" must be specificed", "to");
    163.         }
    164.         FB.AppRequest(
    165.             DirectRequestMessage,
    166.             DirectRequestTo.Split(','),
    167.             "",
    168.             null,
    169.             null,
    170.             "",
    171.             DirectRequestTitle,
    172.             Callback
    173.             );
    174.     }
    175.    
    176.     #endregion
    177.  
    178.     /*#region FB.AppRequest() Friend Selector
    179.        
    180.     public string FriendSelectorTitle = "";
    181.     public string FriendSelectorMessage = "Derp";
    182.     public string FriendSelectorFilters = "[\"all\",\"app_users\",\"app_non_users\"]";
    183.     public string FriendSelectorData = "{}";
    184.     public string FriendSelectorExcludeIds = "";
    185.     public string FriendSelectorMax = "";
    186.  
    187.     private void CallAppRequestAsFriendSelector()
    188.     {
    189.         // If there's a Max Recipients specified, include it
    190.         int? maxRecipients = null;
    191.         if (FriendSelectorMax != "")
    192.         {
    193.             try
    194.             {
    195.                 maxRecipients = Int32.Parse(FriendSelectorMax);
    196.             }
    197.             catch (Exception e)
    198.             {
    199.                 //status = e.Message;
    200.             }
    201.         }
    202.        
    203.         // include the exclude ids
    204.         string[] excludeIds = (FriendSelectorExcludeIds == "") ? null : FriendSelectorExcludeIds.Split(',');
    205.        
    206.         FB.AppRequest(
    207.             FriendSelectorMessage,
    208.             null,
    209.             FriendSelectorFilters,
    210.             excludeIds,
    211.             maxRecipients,
    212.             FriendSelectorData,
    213.             FriendSelectorTitle,
    214.             Callback
    215.             );
    216.     }
    217.     #endregion*/
    218. }
    219.  
     
    Last edited: Aug 12, 2014
  2. NomadKing

    NomadKing

    Joined:
    Feb 11, 2010
    Posts:
    1,461
    Please use Code Tags when posting code on the forums.
     
    AlbertJNT likes this.
  3. AlbertJNT

    AlbertJNT

    Joined:
    Aug 7, 2014
    Posts:
    5
    Do it! Thanks! But, can you help me ?
     
    Last edited: Aug 12, 2014
  4. AlbertJNT

    AlbertJNT

    Joined:
    Aug 7, 2014
    Posts:
    5
    Nobody ?
     
  5. NomadKing

    NomadKing

    Joined:
    Feb 11, 2010
    Posts:
    1,461
    What line numbers do you get the errors on?
     
  6. AlbertJNT

    AlbertJNT

    Joined:
    Aug 7, 2014
    Posts:
    5
    Sorry, I fix them. Thanks!
     
    NomadKing likes this.
  7. FeralLAG

    FeralLAG

    Joined:
    Mar 9, 2014
    Posts:
    1
    How did you solve this?! i have the same problem... :(
     
  8. hzc111

    hzc111

    Joined:
    Jul 15, 2015
    Posts:
    2
    I have the same problem,but i don't know how to solve it.Can you help me?