Hi all
I’m desperately trying to get the content of a Site.fr : Votre domaine et hébergement - Allez en ligne!
in a webgl app…
It does nothing… and give some useless error on my console
Could please anyone give some example on how to achieve this ?
I need the file content to be stored in a simple string…
BTW my biggest problem is that i got no way to debug anything in webgl.
no debug.log output anywhere…
How do you do this guys ?
mgear
October 17, 2021, 2:15pm
3
so does it work in the editor? at least that link seems broken.
webgl debug log output is in the browser console (F12 in most browsers, then Console tab)
to read text data with webrequest,
Hm strangely when i Debug.Log(“my message”); i got nothing at all in my console
Oh sorry for the link it was just an example
Now i made my own Debug.Log class and write output on the 3D screen. It’s far from efficient but at least it allows me to see some debugging messages…
And yes it does work from within the editor when accessing the http file…
Okay… more info now…
With this code on my webgl target:
IEnumerator GetText()
{
UnityWebRequest www = UnityWebRequest.Get("http://www.kleioscope.fr/essais/ReinfoCovid.txt");
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success)
{
LOG.o(www.error);
LOG.o(""+www.result);
}
else
{
// Show results as text
LOG.o(www.downloadHandler.text);
}
}
i recieve unknown error as www.error
and
ConnectionError as www.result .
Everything works fine in the editor but running the app through the U3D index.html on my server refuses to get this file.
http or https leads to the same thing, .htaccess is okay ( and anyway it works in editor ), the file extention ( xml or txt changes nothing )…
I’m totally lost
It looks like a bug in unity webgl target…
mgear
October 17, 2021, 6:28pm
6
see the browser console window, at least on local build its this:
1 Like
omg !!!
It appears there’s something i did not catch…
when i run the app in browser with the full https://www … in the adress bar, all works !
but
when i do the same with kleioscope.fr/essais webrequest returns an error…
I guess i still have many things to learn here
You pointed it right @mgear
Now simply using the “./ReinfoCovid.txt” as the document adress works fine…
I never thought that an absolute full URL would forbid a file access
I spent the whole day on this
And thanks a bunch @mgear
Happy unitying !
Hi
I recommend using the “File Manager for WebGL” package from the Unity Asset Store. It is specifically designed for WebGL apps and allows you to retrieve the content of a file from a URL/user and store it in a string variable within your application. You can find the package at this link: