Search Unity

Live Data JSON to Unity Position

Discussion in 'Scripting' started by eni8ma, Sep 20, 2019.

  1. eni8ma

    eni8ma

    Joined:
    Jul 29, 2019
    Posts:
    6
    Hello I am curious how this would be achieved if possible

    So imagine a JSON file that keeps writing new lines in a server which are positions

    Would it be possible to pull that JSON file from a server and continuously update a Game Object position to match that of the JSON file?

    Any help or directions would be greatly appreciated
     
  2. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    For what purpose? And continuously update, what is changing, is it the JSON file? You might want to check out Unity Remote Config, but not sure about your implementation. Or are you trying to make a multiplayer game and want all users to see the same position? You probably want to use a multiplayer asset instead, if so.
     
    eni8ma likes this.
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    If you're trying to use a file for some form of inter-process or network communication, then JSON wouldn't be what I'd use. If I was crazy enough to do it this way, I'd probably use a CSV.
     
    eni8ma likes this.
  4. eni8ma

    eni8ma

    Joined:
    Jul 29, 2019
    Posts:
    6
    So its for pulling live data. So imagine a tracking device that updates a JSON file with live co-ordinates on a server. I would like to pull that data into unity.
     
  5. eni8ma

    eni8ma

    Joined:
    Jul 29, 2019
    Posts:
    6
    I could have the company provide me a CSV file if it would make it easier to pull the data but would something like this be possible if the CSV keeps being updated live.
     
  6. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    First step seems would be to implement the logic to check a local file continuously, perhaps in your Update() method.
     
  7. eni8ma

    eni8ma

    Joined:
    Jul 29, 2019
    Posts:
    6
    Ok that what I was thinking to do it first locally and then online but it sounds like it might be possible to make it work
    Ideally I would like the data to be translated to the position of a game object in 3D space.
     
  8. JeffDUnity3D

    JeffDUnity3D

    Joined:
    May 2, 2017
    Posts:
    14,446
    Even easier, put 3 text input objects on your scene name posX, posY and posZ. Enter numeric values and move a game object on a button click. Expand from there.
     
    eni8ma likes this.
  9. eni8ma

    eni8ma

    Joined:
    Jul 29, 2019
    Posts:
    6
    Sounds like a great way to start. Thanks so much!
     
  10. condo3000

    condo3000

    Joined:
    May 10, 2020
    Posts:
    2
    Hey eni8ma,

    I am looking to import json from an api and use that for data visualization. How did your project go? Any further news on how to update a game based on data?