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

Question Script doesn't accept JSON file when it's under StreamingAssets folder

Discussion in 'Scripting' started by AnahidE5, Jul 29, 2022.

  1. AnahidE5

    AnahidE5

    Joined:
    Jan 10, 2022
    Posts:
    40
    So I am using a script that accepts a JSON file in the inspector. I can drag and drop any JSON file in my project into that field unless it's under my StreamingAssets and obviously, that is the place I need my data to be. When I copy the JSON file from somewhere else in my project and put in under streaming, even the little icon next to it looks different from other places in the project and it's also different from what the script shows. I've attached a screenshot in case I'm not making much sense. But I just need to know what's happening and why is it that my script does not accept the exact same JSON if it's under StreamingAssets. Thanks.

    Capture.PNG
     
  2. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,148
    Why do you need it in StreamingAssets if you're attaching it to the script?

    Anyways, StreamingAssets is a special folder where the items in it aren't imported into the project, so Unity has no idea what those files actually are. So it doesn't know it's a text file, image, etc. So you can't drag and drop it into the inspector from StreamingAssets.

    https://docs.unity3d.com/Manual/StreamingAssets.html
    First paragraph explains it a little.
     
  3. AnahidE5

    AnahidE5

    Joined:
    Jan 10, 2022
    Posts:
    40
    "The VitalsMonitorScenario scene requires that you have created a StreamingAssets folder in the root of your application’s Assets folder (not the PulsePhysiologyEngine folder). Then copy the Pulse asset Data directory into that folder."

    I'm not sure to be honest. This is what I have received from the developer of the package. So you're saying I should just point to the file in code instead?
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    How do you know it's a JSON issue? You are receiving the error, "Unable to initialize patient", where is that coming from? You've properly placed the Data folder as instructed by the developer.
     
    Bunny83 and AnahidE5 like this.
  5. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,148
    Yes, if this is for an asset, it sounds like the asset maybe already tries to load the file from that folder. As @JeffDUnity3D mentions, where does the error come from? That could be the key to solving the issue. But I don't know the asset or what it is suppose to do.
     
    AnahidE5 likes this.
  6. AnahidE5

    AnahidE5

    Joined:
    Jan 10, 2022
    Posts:
    40
    Thanks all. The developer told me later that I can do either StreamingAssets and hardcode the path or use the inspector. My main question for this thread was just why I can't drag and drop a file from StreamingAssets. I now have a better idea how this folder works.