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.
I must be doing it wrong as I spend hours trying to find what packages to import (using statements). 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.
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.
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
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");
}