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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Google Play Games - Null Reference PlayGamesPlatform

Discussion in 'Scripting' started by xciter_, Apr 20, 2020.

  1. xciter_

    xciter_

    Joined:
    Apr 10, 2019
    Posts:
    6
    Hey everyone,

    Been struggling with this one for about a week now. Searched around on Google, found various different examples but none of them seem to get it working. I've been following the CubicPilot example from the Google Play Services for Unity on Github (https://github.com/playgameservices...r/samples/CubicPilot/Source/Assets/CubicPilot)

    The code that appears to be the problem, is whenever I use the following line...

    Code (CSharp):
    1.                
    2. ((PlayGamesPlatform) Social.Active).SavedGame.OpenWithAutomaticConflictResolution(filename,
    3.                 DataSource.ReadCacheOrNetwork,
    4.                 ConflictResolutionStrategy.UseLongestPlaytime,
    5.                 SavedGameOpen);
    6.  
    I've seen other examples that call the PlayGamesPlatform this way...

    Code (CSharp):
    1.  
    2. PlayGamesPlatform.Instance.SavedGame(...);
    3.  
    but the above code still gives me the same issue which is:
    Object reference not set to an instance of an object.

    UPDATE:
    And just to add...this is my current PlayGamesPlatform setup in case anyone asks if I've enabled saved games...

    Code (CSharp):
    1.                
    2.         PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
    3.             .EnableSavedGames()
    4.             .Build();
    5.  
    6.         PlayGamesPlatform.InitializeInstance(config);
    7.         PlayGamesPlatform.DebugLogEnabled = true;
    8.         PlayGamesPlatform.Activate();
    9.  
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    Best two ways to figure out what the problem is:
    • Put a breakpoint on the problematic line, then check the value of everything that is getting dereferenced on that line to see which is null
    • Similar to above, but with log statements. Debug.Log() everything you are dereferencing on that line and you will find the thing that is null.
    Then when you know which thing is null you will know how to proceed.
     
  3. xciter_

    xciter_

    Joined:
    Apr 10, 2019
    Posts:
    6
    Hey, sorry for the slow update. This issue has now been resolved but I would like to add a follow up question...

    So, it gets rather annoying having to upload the APK to Google when I want to test something using their services. So, instead, I have Unity 'Build and Run' on my device. Problem is though, Social.localUser.Authenticate returns 'False'.

    As soon as the same APK is up on Google, however, it works fine.

    Is there a way I can fix this so I don't have to upload to Google each time?
     
  4. burn_barrel

    burn_barrel

    Joined:
    May 2, 2018
    Posts:
    3

    Im having the same issue. You said that you resolved it but you didn't say how? Could you please update this to say how you resolved it?