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

[RELEASED] Google Sheets For Unity Lite

Discussion in 'Assets and Asset Store' started by Novack, Mar 3, 2014.

  1. ronshalev3d

    ronshalev3d

    Joined:
    Apr 30, 2019
    Posts:
    21
    Hi there
    once again thank you very much for all your support.

    After everything works fine its time for some logic and here i have a small question.
    it's easy to fire a function when the item cannot be found (log to the error response callback when the string is "item not found");
    but there is no info in the documentation what's the error if for some reason there is an internet connection issue and I cannot reach the google sheet.
    could you please elaborate?
     
    Novack likes this.
  2. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    Heya, glad it worked.

    The connection errors can be of two types: network errors, and timeout errors. These are handled at DriveConnection class, and also fire error callbacks. The messages can be seen on lines 29 and 38 of that class respectively.

    Hope it helps!
     
  3. Grazianiale

    Grazianiale

    Joined:
    Dec 31, 2012
    Posts:
    4
    Hi Novack. I purchased the asset more than a year ago, at that time worked just perfect and I didn´t have problems using it. I have tried to use it on a new project but I cant make it works.
    Every time I click to create table or anything from the example I recieve a log message as Incorrect Credentials, I´ve tried to reset the password (but It doesnt appear in the project setting as the manual said), I´ve tried to put passcode as default password, even let It blanck but nothing happens... I´ve double checked url, and spredsheet id.
    I pretty sure that I´m doing something really stupid, but I don´t know what it is...
    May be I am missing something?
    Thanks in advance.
     
  4. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    Hello @Grazianiale, thanks for contacting.

    Starting from the simplest approach: both the webapp passcode and the Unity client passcode match?
    The developer guide is entirely valid up to this day, the webapp passcode will be found here:

    upload_2019-12-2_14-47-41.png


    And the Unity side passcode will be here:

    upload_2019-12-2_14-49-10.png

    Let me know if this helps, otehrwise once the basic stuff is out of the way, we can keep looking.
     
  5. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    The images did not upload, I cant see what you captured. Can you upload again, or use something like imgur and paste the links here?

    What version of the asset are you using, Lite or Full?

    Make sure you download the latest version of whatever version you have, including the latest version of the webapp script (that may need to go into the developer guide and make a new copy of the script).
     
  6. Grazianiale

    Grazianiale

    Joined:
    Dec 31, 2012
    Posts:
    4
    Last edited: Dec 2, 2019
  7. Grazianiale

    Grazianiale

    Joined:
    Dec 31, 2012
    Posts:
    4
    I have the Lite Version: 3.0.1.

    Yes I imported that version and I made a new copy from the link provided in developer guide
     
  8. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    Oh right then, with that cleared, then the missing Script Property seems to be the issue.
    Just click on "Add Row" and write "PASSWORD" in the property column and "passcode" (or whatever you want) in the value column. Then redeploy the webapp.

    You can ignore the difference on the ConnectionData asset, in the picture I was using the full version as example.
     
  9. Grazianiale

    Grazianiale

    Joined:
    Dec 31, 2012
    Posts:
    4
    Genial!!!!! thanks a lot...
    GREAT!!! It works perfect.... Thank you very much... Thanks!!!
     
    Novack likes this.
  10. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    Heads up everyone!

    Its being reported that some Firefox Nightly builds are rejecting Google Sheets For Unity requests on Unity WebGL builds, due to CORS incorrectly filtering Simple Requests. Seems like a browser bug, I will be following, but for the time being please avoid Firefox Nighlty.
     
  11. ronshalev3d

    ronshalev3d

    Joined:
    Apr 30, 2019
    Posts:
    21
    Hi, thanks for the reply
    it turned out that for *some reason* the web service URL on the server that connects between the app and the sheet has changed and forced me to create a new service with new url.
    the change was that the "company name." part was removed from the url
    still, no clew what caused the change but it sees,s like what you said was not the issue this time.
     
  12. tomph

    tomph

    Joined:
    Nov 6, 2013
    Posts:
    33
    Hi @Novack I'm reading your PDF documentation but I can't see any way where I can setup multiple DriveConnections? I have one spreadsheet where I am recording events (writing), but I want to also have a connection to another spreadsheet (different ID) where I can read data. Because Drive.API is static, I'm not sure how I set it up to handle multiple sheets?
     
  13. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    Hello @tomph thanks for contacting.

    What you mention is covered on dev guide from page 3, describing how to create multiple ConnectionData assets. It doesnt elaborate much, because the underlying concept is rather simple: the data for the requests, is holded on the connection data assets, that you can vary as you need.

    GSFU doesnt do this for you, you need to switch the asset as needed, by yourself. However, its simple and just a matter of assigning the required ConnectionData field to the DriveConnection object before you create a request:
    • First you need to create as many connection data assets as you need, then have a collection of references to them somewhere (ie: in DriveConnection class, as the original reference is stored, may be a good place).
    • Then you need to tweak the GSFU code, to switch the connection data dinamically, before using it. The right place to make this will probably be Drive.SetConnectionData() which does precisely what its name says, you would just need to select the desired connection data reference.
    A different, and likely simpler way to do what you need, is instead changing the spreadsheet id, instead of the whole connection data asset! You just need to follow the logic, and change the spreadsheet id before the request is built.

    This is a highly requested feature, so at some point i the future I will add it, but as per de daily work, has been some time since I was able to work on new features for GSFU.

    Hope it helps!
     
    Last edited: Sep 30, 2020
  14. Laaevin

    Laaevin

    Joined:
    Sep 10, 2012
    Posts:
    10
    @Novack I just bought this asset and have already found it very useful and user-friendly, thank you! I do have one question which hopefully has a quick and easy answer that I'm just overlooking. Is there a way in my script to catch the "Object not found." message when trying to use Drive.GetObjectsByField? Basically I'm calling it when the user inputs the player name, and it works great if the user has input the name correctly, but if they've made a typo, the game just sits there. I'd like to have an error message pop up when the object isn't found. And I'd like to have it in my main script (e.g. the SpreadsheetExample.cs script, rather than in the Data.cs script) if at all possible. But I'm not sure how or where in the script to catch the "Object not found." problem. Any guidance would be great!
     
  15. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    Hello @Laaevin, thanks for contacting.

    Indeed, it has a simple solution. Lets take the SpreadsheetExample example as base to elaborate a bit: check how that class (near the top at OnEnable and OnDisable), handles the suscription to Drive.responseCallback to receive the response.

    For convenience, there is another callback to receive and handle the errors: Drive.errorResponseCallback, which will send the error message along with it. So you just need to suscribe to it from your class.

    Rough example:
    Code (CSharp):
    1. private void OnEnable()
    2. {
    3.    // Suscribe for catching cloud ERROR responses.
    4.    Drive.errorResponseCallback+= HandleDriveError;
    5. }
    6.  
    7. private void HandleDriveError(string message)
    8. {
    9.    Debug.Log(message);
    10. }
    Hope it helps!
     
  16. Laaevin

    Laaevin

    Joined:
    Sep 10, 2012
    Posts:
    10
    Works like a charm! Thank you very much for the quick, detailed and helpful response!
     
    Novack likes this.
  17. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    Heads up! The old classic is on sale:

    With 6+ years published and evolving, Google Sheets For Unity Lite is **50% Off** at the Unity Asset Store :)

    Grab it on the asset page: HERE.
     
  18. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    This is the answer to a post in the sister forum thread.
    Answering here as it is the proper place for Google Sheets For Unity Lite questions.
    On with the answers:
    The time it takes to complete a creating, retrieving, updating or deleting operation will highly vary depending on the size of the spreadsheet, the amount of data transmited, and the connectivity of the user with Google. So there is no concrete answer to this question. If you want to test this for yourself, you can check the online demo, its valid for Google Sheets for Unity Lite.
    There is no such thing as a "crash limit" on Google, but you do may hit a possible limit: the number of simultaneous requests.
    The sheet does not need to be shared, so the risk of exposing the sheet itself is null.
    The last time I tested the max size of a file to be created in Drive with a Google Sheets For Unity request was 24MB. In your case you're asking for data to be sent to a spreadsheet, so will never even go near that amount. There is no download limit, but big downloads of course introduce delays on the responses.
    The handling of data is up to you, GSFU doesnt handle the concept of "player", think of a simplified database. You can check the online reference docs here (the marked * calls are not available on lite edition).

    Also please note Google Sheets For Unity is recommended for experience programmers.
    Hope it helps!
     
  19. megatron0

    megatron0

    Joined:
    Nov 19, 2018
    Posts:
    27
    thanks for reply
    iam not sure how to move post so i just deleted it.
    i have checked the online api and i have one more question.
    is there an addtional source inside the asset that provides more info about responses amd call backs?
    because i will do requests using getobjectsbyfield method alot so i want to know if it possible to see of the callback is null or no
    thanks in advance
     
  20. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    @megatron0 the source is included of course, and there are a few examples to inspect and follow how to handle response callbacks, although is quite simple: the callback will return always, either with the found content or with an error. In the case of no objects found with the specified criteria, will return an error with a msg "Object not found.".
     
  21. megatron0

    megatron0

    Joined:
    Nov 19, 2018
    Posts:
    27
    ok thanks for help i will be buying the asset when i start the database part
     
    Novack likes this.
  22. PaulDyatlov

    PaulDyatlov

    Joined:
    Jul 6, 2019
    Posts:
    24
    CreateObjects returns this. Any help?


    Undefined server response:
    <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Fehler</title><style type="text/css">body {background-color: #fff; margin: 0; padding: 0;}.errorMessage {font-family: Arial,sans-serif; font-size: 12pt; font-weight: bold; line-height: 150%; padding-top: 25px;}</style></head><body style="margin:20px"><div><img alt="Google Apps Script" src="//ssl.gstatic.com/docs/script/images/logo.png"></div><div style="text-align:center;font-family:monospace;margin:50px auto 0;max-width:600px">TypeError: Cannot read property &#39;length&#39; of undefined (Zeile 637, Datei &quot;Code&quot;)</div></body></html>
    UnityEngine.Debug:Log (object)
    GoogleSheetsForUnity.Drive:UpdateStatus (string[]) (at Assets/Google Sheets For Unity/Scripts/Drive.cs:758)
    GoogleSheetsForUnity.Drive:HandleError (string,single) (at Assets/Google Sheets For Unity/Scripts/Drive.cs:746)
    GoogleSheetsForUnity.Drive:processResponse (string,single) (at Assets/Google Sheets For Unity/Scripts/Drive.cs:712)
    GoogleSheetsForUnity.DriveConnection/<CoExecuteRequest>d__2:MoveNext () (at Assets/Google Sheets For Unity/Scripts/DriveConnection.cs:45)
    UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)
     
  23. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    Hello @unity_dn7k0hEaOzg_2w, not sure by what you pasted, but looks like something fundamental is missing or incorrectly setup.

    My advise would be to install the asset in an empty Unity project, and follow the steps on the developer guide to properly setup and deploy. Then make sure the included examples work.

    Once you have it working as expected, then you can integrate into your own project with more confidence on how to work with it.
     
  24. PaulDyatlov

    PaulDyatlov

    Joined:
    Jul 6, 2019
    Posts:
    24
    @Novack Thanks for the reply
    Seems like it's the HTML error response. Unfortunately it's not working on an empty project as well, CreateObject runs just fine, CreateObjects throws an error even on the included examples.

    If you need any additional information, feel free to ask.
     
  25. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    Hello again @unity_dn7k0hEaOzg_2w, good catch!

    Luckily I was able to amend it on the server side, so just sent an updated version of the webapp service script, please make a new copy and deploy the new one, it should be working now.
     
  26. PaulDyatlov

    PaulDyatlov

    Joined:
    Jul 6, 2019
    Posts:
    24
    @Novack Just tested that, works like a charm. Thanks for the quick fix.
     
  27. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    Thats great! Thanks for the report and for letting me know it works as expected :)
     
  28. eovento

    eovento

    Joined:
    Feb 22, 2018
    Posts:
    38
    Good morning, people!

    I'm a new super happy user of Google Sheets fo Unity. :)
    Thank you SO MUCH for this asset.

    There are a few things I would like to understand, as I couldn't find on the documentation:

    -In my script, when I'm about to add the first row/object, I create the Table on the line before. And this gives me an error as by the time the second line processes, the table wasn't existent yet (because although the line before was properly computed, it has a delay from Google side). Is there a way to properly wait for a response (for the table to be existent) before actually trying to add the first object into it?

    -My second question is about the Headers.
    Is it any possible to change what we read on the spreadsheet (column titles) without changing its "value" (the original string the asset is going to look for)?
    I mean... I have renamed all my variables to uppercase (like global variables look like) just for the headers to look a bit like I would like them to look. But, still, they obviously have underscore, and I just wanted the table headers to look neat.
    If I change them, the next uploaded object will not recognize its proper fields/columns anymore.

    Anyhow, I'm absolutely satisfied with the tool!
    Thank you, and wish everyone a great week,

    Daniel
     
  29. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    Hello @eovento thank you very much for your very kind words! :)

    Indeed the responses from the webapp service are async, so in order to make a call that depends on a GSFU api call, you need to suscribe to the events available precisely for that purpose. Look into the examples, how they suscribe to the event Drive.responseCallback and receive the responses on HandleDriveResponse. Then you can decide what to do accordingly, after receiving the answer from Google servers.

    Regarding the headers: as you have found already, you can add formatting (font size and style), but the text needs to match exactly the name of the fields on the objects defined in Unity. That was on purpose, for simplicity.

    However if you want to elaborate on that you have two paths: you can modify the webapp code that generates the json and handle it differently (some add an extra row of space for defining the type, or retrieve a spreadsheet note for that, etc). Or you can also use a different json parsing library on the Unity side (like SimpleJson or Newtonsoft), that lets you map different field names, or use dynamic fieldnames directly.

    Just remember taht if you change the code for the webapp, you need to redeploy it!

    Thanks again for the kind feedback, and good luck with your project!
     
  30. Mojo-Game-Studio

    Mojo-Game-Studio

    Joined:
    Sep 18, 2015
    Posts:
    111
    Hi I seem to be having problems with step 2 in the deployment section, I clicked the link in the pdf and it opened a script on google, but when I try to change the passcode I get this screen:

    Any advice?
     
    Last edited: Mar 11, 2021
  31. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    Hi @Mojo-Game-Studio,

    That is because that is not your copy. You should be doing your own copy of the script project, then you should be able to edit the script properties, and create the passcode property.

    PS: would you be so kind as to remove the the image of your post? It contains material that is part of the package and should not be shared. Thanks!
     
    Last edited: Mar 19, 2021
  32. dogsaregreat

    dogsaregreat

    Joined:
    Sep 5, 2018
    Posts:
    21
    Hello @Novack , I'm trying to test a Google Sheets with your demo from itch.io and when i input my spreadsheet ID, I get this error

    Code (CSharp):
    1. `uncaught typeerror: cannot read property style 'style' of null`
     

    Attached Files:

  33. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    Hello people, apologies for the leave of absence. I had to attend some family and health issues, and had no opportunity or time aside from that to offer the usual support for Google Sheets For Unity. I will be slowly catching up.

    @dogsaregreat, I will check that asap.
     
  34. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    @dogsaregreat thanks for contacting, and I appreciate your patience.

    I have solved some issues with the webgl demo (also I had inadvertently removed the server side deployment, which is also back online), so everything should be fine as far as the demo at itch.io.
     
  35. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    Heads up folks!

    There is a missing feature of the new Google editor that wont let you set the property used for the password on new deployments.

    Google still allows to switch back to the old editor, so one solution is to momentarily get back to the legacy editor in order to set the property.

    I also have added new code to the bottom of the DriveForUnitySocket script, two convenient methods to overcome the situation until Google fixes the new lacking editor:

    Code (CSharp):
    1. function GetScriptProperties()
    2. {
    3.   var properties = PropertiesService.getScriptProperties().getProperties();
    4.   Logger.log(properties)
    5. }
    6.  
    7. function SetScriptProperties()
    8. {
    9.   var key = "PASSWORD";
    10.   var value = "passcode";    // Change this value to your own passcode.
    11.   PropertiesService.getScriptProperties().setProperty(key, value);
    12.  
    13.   GetScriptProperties();
    14. }
    You can retrieve a new copy of the script as usual, or you can simply copy and paste this code on your own, and paste it at the bottom of the script. No need to redeploy, as this is code that will only work for the devs:
    1. If you pasted the code yourself, first thing: hit save button (or CRTL+S).
    2. Then go to the method selection drop down at the toolbar, and select SetScriptProperties.
    3. In the code, go to the SetScriptProperties() method, and in the "value" variable write your own passcode.
    4. Click "Run" on the toolbar.
    upload_2021-8-10_19-14-2.png


    That should set the property!
     
  36. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,818
    Hello,

    Just bought this and finished the setup. But when I call in on Start I get this:

    Code (CSharp):
    1. MissingReferenceException: The object of type 'DriveConnection' has been destroyed but you are still trying to access it.
    2. Your script should either check if it is null or you should not destroy the object.
    3. UnityEngine.MonoBehaviour.StartCoroutine (System.Collections.IEnumerator routine) (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/MonoBehaviour.bindings.cs:88)
    4. GoogleSheetsForUnity.DriveConnection.ExecuteRequest (UnityEngine.Networking.UnityWebRequest www, System.Collections.Generic.Dictionary`2[TKey,TValue] postData) (at Assets/Google Sheets For Unity/Scripts/DriveConnection.cs:15)
    5. GoogleSheetsForUnity.Drive.CreateRequest (System.Collections.Generic.Dictionary`2[TKey,TValue] dataForm, System.Boolean runtime) (at Assets/Google Sheets For Unity/Scripts/Drive.cs:367)
    6. GoogleSheetsForUnity.Drive.GetObjectsByField (System.String objTypeName, System.String searchFieldName, System.String searchValue, System.Boolean runtime) (at Assets/Google Sheets For Unity/Scripts/Drive.cs:172)
    7.  
    I didn't destroy the object though, it's still clearly in the scene.

    Thanks,
    jrDev
     
  37. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    Hey @jrDev thanks for contacting!

    I presume that you're using it in your own project, can you try first testing the included examples (probably the "Sheets Example" escene would be the best candidate), and tell me if you get any issue with that one?

    The examples should work out of the box after completing the webapp setup, so that should tell you if the asset is fine, or something is missing on the web service side.

    On the other sid, if the example scene works fine, then is something related to the setup of your own local scene thats missing.

    Hope it helps!
     
  38. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,818
    No the example does the same thing…

    I checked with a debug log at line 367 of Drive.cs and the “driveConnectionRuntime” variable is null.

    Code (CSharp):
    1.  MissingReferenceException: The object of type 'DriveConnection' has been destroyed but you are still trying to access it.
    2. Your script should either check if it is null or you should not destroy the object.
    3. UnityEngine.MonoBehaviour.StartCoroutine (System.Collections.IEnumerator routine) (at /Users/bokken/buildslave/unity/build/Runtime/Export/Scripting/MonoBehaviour.bindings.cs:88)
    4. GoogleSheetsForUnity.DriveConnection.ExecuteRequest (UnityEngine.Networking.UnityWebRequest www, System.Collections.Generic.Dictionary`2[TKey,TValue] postData) (at Assets/Google Sheets For Unity/Scripts/DriveConnection.cs:20)
    5. GoogleSheetsForUnity.Drive.CreateRequest (System.Collections.Generic.Dictionary`2[TKey,TValue] dataForm, System.Boolean runtime) (at Assets/Google Sheets For Unity/Scripts/Drive.cs:368)
    6. GoogleSheetsForUnity.Drive.GetObjectsByField (System.String objTypeName, System.String searchFieldName, System.String searchValue, System.Boolean runtime) (at Assets/Google Sheets For Unity/Scripts/Drive.cs:172)
    7. GoogleSheetsForUnity.SpreadsheetsExample.RetrievePlayer () (at Assets/Google Sheets For Unity/Examples/Spreadsheet Example/SpreadsheetsExample.cs:151)
    8. GoogleSheetsForUnity.SpreadsheetsExample.OnGUI () (at Assets/Google Sheets For Unity/Examples/Spreadsheet Example/SpreadsheetsExample.cs:96)
    9.  
    This is Unity 2021.1.

    I thought the DriveConnection was being destroyed so I added DontDestroyOnLoad to the script but that still doesn’t help.

    Thanks,
    jrDev
     
    Last edited: Aug 21, 2021
  39. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    @jrDev I just deleted my previous post, because I think I have a clue: may be the case that you're using fast Play Mode options?

    upload_2021-8-21_12-57-21.png

    If thats the case, static fields may end up in an outdated state, and that may be the reason for driveConnectionRuntime not being properly initiated.

    If thats the scenario, you can quickly solve it by adding the following code at the very top of the method SetConnectionData(bool runtime),
    Code (CSharp):
    1. #if UNITY_EDITOR
    2.             _connectionData = null;
    3. #endif
    That will force the editor to reassign the connection data every time, and will solve the issues with hot play.

    Hope it helps!
     
    Last edited: Aug 21, 2021
    crafTDev likes this.
  40. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,818
    Hello,

    So I had enter Play mode options checked but not the Reload Domain or Reload Scene, I turn it off, and entering play mode is slower but I don't get errors anymore. If I have it checked and put that code you posted it works too! So it looks like that's the cause (and maybe the cause for other issues unrelated). I didn't even know Unity had that option or dont remember turning it on at all. I like to quickly get into Play Mode though so I will add the code. Hopefully you can add that officially just in case.

    On another note, when it comes to making the calls, I don't know how to decipher the Parameters being used here; a little more explanation can help a lot (can you visually show me what these pertain to when actually looking at a Google Sheet).
    For eg:
    GetObjectsByField(
    Obj Type Name: What should I actually put here
    Search Field Name: What's a field name in the Google Sheet?
    Search Value: Same as above

    I am currently just guessing right now.

    Thanks,
    jrDev
     
  41. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    Glad it worked then :) I will most definitively add that code in future releases.

    You should not be guessing! :)

    You can check the included Developer Guide for general concepts and webservice setup procedure. Also there as well, you will notice a link to the API reference (but I'll paste it here as well):
    Google Sheets For Unity Online API Reference

    Also each method is documented on the code itself, you should be viewing relevant info on the autocomplete-hint if you're using any modern code IDE, like so, when steping through the parameters:
    upload_2021-8-21_16-36-44.png

    That being said, the underlying concept is the universal one for data tables handling: a row in the table (a spreadsheet on this case) is considered an object, with each column considered a field. The field name is obtained from the table headers. So a table headers match a class or struct definition in Unity, and each content row, ends up being an object.

    Again, all this becomes pretty clear if you study the API reference, and then go around a bit under the hood with the examples code.

    Hope it helps!
     
  42. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,818
    Hello,

    So I already went through the setup process with the docs, was just confused how the calls work and the API is still not clear to me (I don’t do Spreadsheets) so let me attempt if I am doing this correctly:

    Obj Type Name: Sheet Name? Eg. Sheet1
    Search Field Name: Letters going across? Eg B
    Search Value: Numbers going down? Eg. 3

    So the B3 cell will be selected?

    EDIT: Looks like this is the correct way:
    Object Type Name: Name of the Sheet to search
    Search Field Name: The Column to search
    Search Value: The value to search for

    And with all that info, it will spit out the entire row when you use DataContainer.payload

    PS: Your help was fast and great and the asset now works like a charm!!! Can't believe I can retrieve data like this without any input authorization from Google! I have already parsed all my data!

    Thanks,
    jrDev
     
    Last edited: Aug 22, 2021
  43. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    Precisely :)

    Very glad it worked, good luck!
     
  44. Laaevin

    Laaevin

    Joined:
    Sep 10, 2012
    Posts:
    10
    This asset is so great! I've been using it for years!
    Usually I use CreateObject, and it works like a treat! However, today I tried (for the first time) to use CreateObjects, and I believe I have a user error situation I was hoping you could help me with. I've looked over the API, the examples and this forum, and I'm sure I'm just not doing it right. I think the problem is that I'm not converting my data into the correct format. Here is what I have right now:

    Code (CSharp):
    1. public void SubmitData()
    2.         {
    3.             dataToSave[0, 0] = "email";
    4.             dataToSave[1, 0] = "date";
    5.             dataToSave[2, 0] = "time";
    6.             dataToSave[3, 0] = "tTaken";
    7.             dataToSave[4, 0] = "what";
    8.             dataToSave[5, 0] = "score";
    9.             dataToSave[6, 0] = "other";
    10.             for (int y = 1; y < dataToSave.GetLength(1); y++)
    11.             {
    12.                 dataToSave[0, y] = fileContent[0, y];
    13.                 dataToSave[1, y] = System.DateTime.UtcNow.ToLocalTime().ToString("MM/dd/yyyy");
    14.                 dataToSave[2, y] = System.DateTime.UtcNow.ToLocalTime().ToString("HH:mm");
    15.                 dataToSave[3, y] = "NA";
    16.                 dataToSave[4, y] = "Attendance";
    17.                 dataToSave[5, y] = attendancePoints[y-1] + "";
    18.                 dataToSave[6, y] = "NA";
    19.             }
    20.             string jsonData = JsonUtility.ToJson(dataToSave);
    21.             Drive.CreateObjects(jsonData, "RawData", true);
    22.         }
    Can you please point me in the right direction?
     
    Novack likes this.
  45. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    Hello @Laaevin, thank you for the kind words. Reading cases like yours make my day a little happier :)

    So regarding your case, the API is expecting an array of objects, but you're passing it a matrix (or two-dimensional array) instead. Have this sample code as guide:
    Code (CSharp):
    1. private void SaveData()
    2. {
    3.     int yourDataSetCount = 2;
    4.     YourDataType[] dataToSave = new YourDataType[yourDataSetCount];
    5.  
    6.     for (int i = 0; i < dataToSave.Length; i++)
    7.     {
    8.         dataToSave[i] = new YourDataType()
    9.         {
    10.             email = "email@something.com",
    11.             date = System.DateTime.UtcNow.ToLocalTime().ToString("MM/dd/yyyy"),
    12.             time = System.DateTime.UtcNow.ToLocalTime().ToString("HH:mm"),
    13.             tTaken = "NA",
    14.             // ...etc.
    15.         };
    16.     }
    17.  
    18.     // Get the json string of the objects.
    19.     string dataToSaveJson = JsonUtility.ToJson(dataToSave);
    20.  
    21.     Debug.Log($"Sending data to the cloud: {dataToSaveJson}");
    22.     // Save the objects on the cloud.
    23.     Drive.CreateObjects(dataToSaveJson, "YourDataType");
    24. }
    So you have individual objects in an array, the convert that to json, and thats what you send.
    Hope to one day find the time to elaborate on the new version and improve this a little :)

    Hope it helps!

    PS: code will likely contain issues, I typed it on notepad++ just as a guide!
     
  46. justifun

    justifun

    Joined:
    Apr 2, 2013
    Posts:
    21
    I've tried following the tutorial 3 times now but keep getting this error when trying to use the create table or create player button in the example scene

    Undefined server response:
    <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.com/docs/script/images/favicon.ico"><title>Error</title><style type="text/css" nonce="f5XkJnIlMc31Y-Gww_cSRQ">body {background-color: #fff; margin: 0; padding: 0;}.errorMessage {font-family: Arial,sans-serif; font-size: 12pt; font-weight: bold; line-height: 150%; padding-top: 25px;}</style></head><body style="margin:20px"><div><img alt="Google Apps Script" src="//ssl.gstatic.com/docs/script/images/logo.png"></div><div style="text-align:center;font-family:monospace;margin:50px auto 0;max-width:600px">Script function not found: doPost</div></body></html>
    UnityEngine.Debug:Log (object)
    GoogleSheetsForUnity.Drive:UpdateStatus (string[]) (at Assets/Google Sheets For Unity/Scripts/Drive.cs:758)
    GoogleSheetsForUnity.Drive:HandleError (string,single) (at Assets/Google Sheets For Unity/Scripts/Drive.cs:746)
    GoogleSheetsForUnity.Drive:processResponse (string,single) (at Assets/Google Sheets For Unity/Scripts/Drive.cs:712)
    GoogleSheetsForUnity.DriveConnection/<CoExecuteRequest>d__2:MoveNext () (at Assets/Google Sheets For Unity/Scripts/DriveConnection.cs:42)
    UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)
     
  47. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    Hello @justifun thanks for contacting.

    The error in Unity is simple enough, you need to deply the webapp. If you do it, apparently something went wrong. The details are in the Developer Guide, and if you have questions, feel free to contact me to the support email.

    Hope it helps!
     
  48. devPatrick

    devPatrick

    Joined:
    Sep 28, 2018
    Posts:
    11
    Can this asset create sheets at runtime? In other words, not just save to an existing sheet, but create a new sheet (at runtime) then modify that new sheet?
     
  49. Novack

    Novack

    Joined:
    Oct 28, 2009
    Posts:
    840
    Hello @devPatrick, thanks for contacting.
    Yes, of course :)
     
  50. oliver_unity892

    oliver_unity892

    Joined:
    Oct 28, 2019
    Posts:
    91
    Hi.

    In the deployment section of the manual, it says that clicking the link to the script creates a copy of it. Should I see that in my Google Drive or am I meant to paste the contents of that script to a file in my google drive?

    It doesn't appear in my drive, or in my AppScripts "shared with me" section.

    Olly
     
    Last edited: Dec 21, 2022