Search Unity

Troubles with WWW

Discussion in 'Scripting' started by UnityUser9860, Oct 29, 2017.

  1. UnityUser9860

    UnityUser9860

    Joined:
    Dec 8, 2015
    Posts:
    179
    Hello!
    Im trying to download a simple text file from github here using the WWW API but its not working and throwing this error:

    Code (CSharp):
    1. NullReferenceException: (null)
    2. UnityEditor.SerializedObject..ctor (UnityEngine.Object[] objs, UnityEngine.Object context) (at C:/buildslave/unity/build/artifacts/generated/common/editor/SerializedPropertyBindings.gen.cs:87)
    3. UnityEditor.Editor.GetSerializedObjectInternal () (at C:/buildslave/unity/build/artifacts/generated/common/editor/EditorBindings.gen.cs:193)
    4. UnityEditor.Editor.get_serializedObject () (at C:/buildslave/unity/build/artifacts/generated/common/editor/EditorBindings.gen.cs:185)
    5. UnityEditor.MaterialEditor.OnEnable () (at C:/buildslave/unity/build/Editor/Mono/Inspector/MaterialEditor.cs:1773)
    And my code is:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5.  
    6. public class LogUpdater : MonoBehaviour {
    7.     public string url = "https://gist.githubusercontent.com/Proxz/27d9a6bc8b4e2b39a0063e66db4dfe90/raw/1c3bb5889cc41d8e719993ea0d38b6e5e403ce75/conradupdate.txt";
    8.     public string recived = "";
    9.     public byte[] test;
    10.  
    11.     void Start()
    12.     {
    13.         StartCoroutine(DownloadLog());
    14.     }
    15.  
    16.     IEnumerator DownloadLog()
    17.     {
    18.         WWW www = new WWW(url);
    19.         yield return www;
    20.         Text text = GetComponent<Text>();
    21.         text.text = www.text;
    22.         recived = www.text;
    23.     }
    24.  
    25. }
    26.  
    Im pretty sure its because the url dosn't contain "www." but I dont know a solution.
    Please help thank you :p
     
  2. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    The code snippet is most-likely not involved. Check the stack-trace, which indicates that the error happens during OnEnable in the material editor. This may be a bug on Unity's side.
     
    Last edited: Oct 29, 2017
  3. UnityUser9860

    UnityUser9860

    Joined:
    Dec 8, 2015
    Posts:
    179
    yeah but if i download a direct txt file @Suddoha then it work perfectly
     
  4. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    That might be coincidence. Have you tried to step-through using the debugger?
    As mentioned, the error originates in the MaterialEditor.

    Also, which version are you using? A quick search brought up similar issues that also originated in the same file, some of them should have been fixed in recent versions and only occured in particular situations.