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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Coroutine working in the Unity Editor, but not when built and deployed to the Oculus Go

Discussion in 'Scripting' started by curtehs, Jul 12, 2018.

  1. curtehs

    curtehs

    Joined:
    Sep 24, 2014
    Posts:
    5
    I have a coroutine that just triggers off a VFX and SFX on load:

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using System.IO;
    6. using System.Linq;
    7. using UnityEngine.UI;
    8. public class QuizManager : MonoBehaviour {
    9.    
    10.     [SerializeField]
    11.     public List<Question> Questions;
    12.     public ParticleSystem[] StartParticles;
    13.     public AudioSource[] startAudio;
    14.     // Use this for initialization
    15.     void Start () {
    16.         Questions = File.ReadAllLines("Assets/Questions.csv")
    17.             .Skip(1)
    18.             .Select(v => Question.FromCsv(v))
    19.             .ToList();
    20.         StartCoroutine (onInitLoad ());
    21.     }
    22.    
    23.     // Update is called once per frame
    24.     void Update () {
    25.        
    26.     }
    27.     IEnumerator onInitLoad(){
    28.         yield return new WaitForSecondsRealtime (2f);
    29.         foreach (AudioSource a in startAudio) {
    30.             a.Play ();
    31.         }
    32.         foreach (ParticleSystem p in StartParticles) {
    33.             p.Play ();
    34.         }
    35.         FindObjectsOfType<Text>()[0].text = "RAN";
    36.         FindObjectsOfType<Text>()[1].text = "RAN";
    37.     }
    38. }
    39. [System.Serializable]
    40. public class Question
    41. {
    42.     string Country;
    43.     string FilePath;
    44.     string Answer1;
    45.     string Answer2;
    46.     string Answer3;
    47.     public static Question FromCsv(string csvLine)
    48.     {
    49.         string[] values = csvLine.Split(',');
    50.         Question q = new Question();
    51.         q.Country = values[0].ToString();
    52.         q.FilePath = values [1].ToString ();
    53.         q.Answer1 = values [2].ToString ();
    54.         q.Answer2 = values [3].ToString ();
    55.         q.Answer3 = values [4].ToString ();
    56.         return q;
    57.     }
    58. }
    59.  

    This is triggered in the start method using StartCoroutine(onInitLoad()), this works perfectly and as expected in the Editor and Play mode., but not when built and deployed. Any ideas why? This is my whole scrip.
     
  2. curtehs

    curtehs

    Joined:
    Sep 24, 2014
    Posts:
    5
    FIXED: My code wasn't finding the csv file on android - erroring and not running the coroutine.
     
    Lurking-Ninja likes this.
  3. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,900
    I think your text file load is failing. I'm not sure, because I have never tried to load a text file just like that.
    https://docs.unity3d.com/Manual/LoadingResourcesatRuntime.html

    Check out your logs and it will tell you what's the problem in runtime. https://docs.unity3d.com/Manual/LogFiles.html
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    I haven't used oculus before, but I'm going to take a possible guess that it might be getting stuck on File.ReadAllLines

    It's possible that like Android, oculus doesn't maintain it's file structure which means you wouldn't be able to access Assets/Questions.csv

    You should put Questions.csv into StreamingAssets and access it there, although you may have to use www or unitywebrequest to access it from that location.

    Nevermind, looks like it's all fixed now. lol
     
  5. curtehs

    curtehs

    Joined:
    Sep 24, 2014
    Posts:
    5
    StreamingAssets? Is that just a folder?
     
  6. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,140
    https://docs.unity3d.com/Manual/StreamingAssets.html

    It's a special folder that doesn't import the file (no import settings), but any file in the folder will be included in the build.

    It can be accessed through Application.streamingAssetsPath as they mention in the doc. Interesting enough, I haven't really look at their doc description. It does claim the files are placed in the normal filesystem on the target.