Can someone share an example about how to use VRCStringDownloader.LoadUrl

Hello, I try to use VRCStringDownloader.LoadUrl in a script load a string from a url.

According docs I should use VRCStringDownloader.LoadUrl

If I add this line https://docs.vrchat.com/docs/string-loading(url), How can I declare url?
I try something like this but return the error that “string can not be converted to url…”

This code obviously is not working :wink:

url ="https://....";(
the string=VRCStringDownloader.LoadUrl(url)

Can someone share a basic example to load a url and save its content into string?

Thanks in advance

You have to use string to create VRCUrl object, and use that as the URL for the get function.

https://udonsharp.docs.vrchat.com/vrchat-api/#vrcurl

Thank’s for reply…

I try this, but returns error

VRCUrl("https...")

According to the docs, it says that the VRCUrl object cannot be constructed at runtime, so you might need to look closely at when and where your making this call. Alternatively, it says that you can use a VRCInputField to construct a VRCUrl, so that might be a thing you need to do - create a ‘hidden’ VRCInput object somewhere, set it to your URL, then call the Get() method on it to get a VRCUrl object from the return.

Thanks a lot, finally the problem was that I didn’t define IUdonEventReceiver

If it helps anyone, here is the code that works for me :wink:


public String solution;
 public VRCUrl url=null;
  private IUdonEventReceiver udonEventReceiver;





.....
inside Void start

var url2=url.Get();
Debug.Log("load url "+url2);
 udonEventReceiver = (IUdonEventReceiver)this;
VRCStringDownloader.LoadUrl(url,udonEventReceiver );






outsiede  void start 

public void OnStringLoadSuccess(IVRCStringDownload result)
{
solution=result.Result;
Debug.Log("result from url "+solution);
}
2 Likes

I must be doing it wrong as I spend hours trying to find what packages to import (using statements). :face_with_thermometer: Thus, sharing my clip based on the above…

Per UI setup, created a VRCUrlInputField by adding a normal UI input field in the scene Hierarchy, removing the InputField component, then adding a VRCUrlInputField component, re-attaching the Text and PlaceHolder - per Vowgan VR’s Scripting for Video Players tutorial ( https://www.youtube.com/watch?v=6fqFmqBDSNU ).

using UdonSharp;
using UnityEngine;
using UnityEngine.UI;
using VRC.SDKBase;
using VRC.SDK3.StringLoading; // for VRCStringDownloader
using VRC.Udon.Common.Interfaces; // for IUdonEventReceiver
using VRC.SDK3.Components; // for VRCUrlInputField

public class TestExtRequest
    : UdonSharpBehaviour
{
    [SerializeField] private VRCUrlInputField inputField;
    [SerializeField] private Text text;

    public void SendTestRequest()
    {
        VRCUrl url = inputField.GetUrl();
        IUdonEventReceiver udonEventReceiver = (IUdonEventReceiver) this;
        VRCStringDownloader.LoadUrl(url, udonEventReceiver);
    }

    public override void OnStringLoadSuccess(IVRCStringDownload result)
    {
        text.text = result.Result;
    }
}

Note: URLs must be secure (https). (API notes require unsafe URLs also, depending on URL…?)

Now just hoping at some point they allow dynamic URLs, post data, etc - as this has potential to allow for web-service interactions which would open up soooo many possibilities … one of the biggest being persistence.

Thanks!

Aside: Per the idea of setting the value on a hidden VRCUrlInputField - noted by @FalconiRabbit - I tried to set the value (on the visible one) but couldn’t find a way to do so, tried–

  • VRCUrlInputField text attribute fails to compile / not accessible.
  • Setting inputField.textComponent.text - value did not change.
  • Setting text on a direct reference to the Text field - value did not change.

If anyone has found a way otherwise, give a yell…

i have spent days trying to get vrcstringdownloader working in udonsharp but i kept getting compile errors
so what i ended up doing was creating a udon graph program that would have vrcstringdownloader on it with the output attached to a public variable and call it from a udonsharp
this is udon graph asset i used https://cdn.magma-mc.net/Unity/Udon/StringDownloader.asset

and the udonsharp

using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;

public class StringDownloadText: UdonSharpBehaviour
{
    [Tooltip("StringDownloader UdonGraph Program")]
    [SerializeField] public UdonBehaviour StringDownloader;
    [Tooltip("URL For Text File")]
    [SerializeField] public VRCUrl DataURL = new VRCUrl("https://magmamc.dev/ExampleText.txt");
    /// <summary>
        /// Function is called when the config string has finished downloading
        /// </summary>
        /// <param name="Data"></param>
    public virtual void OnStringDownloaded(string Data)
    {
        Debug.Log(Data);
    }

    public void OnStringFailed() =>
        Debug.LogError($"Failed To Download String From '{StringDownloader.GetProgramVariable("URL")}'");

    public void Start()
    {
        StringDownloader.SetProgramVariable("Reciever", this);
        StringDownloader.SetProgramVariable("OnFinishedEvent", nameof(Internal_StringDownloaded));
        StringDownloader.SetProgramVariable("URL", DataURL);

        StartDownload();
    }
    public void Internal_StringDownloaded()
    {
        string DownloadedString = (string)StringDownloader.GetProgramVariable("StringDownloaded");
        OnStringDownloaded(DownloadedString);
    }

    public void StartDownload() =>
        StringDownloader.SendCustomEvent("InvokeDownload");
}