- Home /
UnityEngineInternal.WebRequestUtils.MakeInitialUrl throwing IndexOutOfRangeException
I am trying to submit data to a google form from Unity using the tutorial here. I am not sure why I am getting index out of range for some internal method called MakeInitialUrl, even though I am not using any Array. I couldn't even find any documentation regarding this method anywhere. https://stackoverflow.com/questions/49825428/unityengineinternal-webrequestutils-makeinitialurl-throwing-indexoutofrangeexcep
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
/// <summary>
/// This class handles the in game survey system.
/// The main menu game object should not be enabled when using this!
/// </summary>
public class Survey : MonoBehaviour
{
public Canvas[] screens;
// Background Info
public InputField ageInput;
public Dropdown genderInput;
public Dropdown schoolInput;
public InputField gradeInput;
public Dropdown gamerInput;
public InputField gameTimeInput;
// String to be sent to Sheets
private static ArrayList sheets = new ArrayList();
WWWForm surveyForm;
[SerializeField]
private string BASE_URL = "https://docs.google.com/forms/d/e/1FAIpQLSfAaFaebUfUc2ywQsXYXgnLptFWqyHawAqAHAy-0XooFMA0Wg/formResponse";
// Use this for initialization
void Start()
{
updating = false;
currentStatus = "Offline";
surveyForm = new WWWForm();
changeScreens();
}
IEnumerator Post()
{
byte[] rawData = surveyForm.data;
WWW www = new WWW(BASE_URL, rawData);
yield return www;
}
public void hitContinueBackgroundScreen()
{
surveyForm.AddField("entry.193768661", ageInput.text);
surveyForm.AddField("entry.1322511470", genderInput.value);
surveyForm.AddField("entry.2009551840", schoolInput.value);
surveyForm.AddField("entry.1682279685", gamerInput.value);
surveyForm.AddField("entry.309799851", gameTimeInput.text);
StartCoroutine(Post());
}
}
IndexOutOfRangeException: Array index is out of range. UnityEngineInternal.WebRequestUtils.MakeInitialUrl (System.String targetUrl, System.String localUrl) (at C:/buildslave/unity/build/Modules/UnityWebRequest/Public/WebRequestUtils.cs:515) UnityEngine.Networking.UnityWebRequest.set_url (System.String value) (at C:/buildslave/unity/build/Modules/UnityWebRequest/Public/UnityWebRequest.bindings.cs:326) UnityEngine.Networking.UnityWebRequest..ctor (System.String url, System.String method) (at C:/buildslave/unity/build/Modules/UnityWebRequest/Public/UnityWebRequest.bindings.cs:138) UnityEngine.WWW..ctor (System.String url, System.Byte[] postData) (at C:/buildslave/unity/build/Modules/UnityWebRequestWWW/Public/WWW.cs:76) Survey+c__Iterator0.MoveNext () (at Assets/Survey/Survey.cs:76) UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17) UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) Survey:hitContinueBackgroundScreen() (at Assets/Survey/Survey.cs:146) UnityEngine.EventSystems.EventSystem:Update()
Debug logs returned with following data:
gamerInput.value === 1
gameTimeInput.text === 230
schoolInput.value ===== 6
genderInput.value ==== 3
ageInput.text ==== 22
Answer by Runalotski · Apr 13, 2018 at 11:35 PM
Hi From the stack trace you posted I can see this
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator) Survey:hitContinueBackgroundScreen() (at Assets/Survey/Survey.cs:146)
This is saying that the fault comes from a script called Survey in a function hitContinueBackgroundScreen() which is on line 146.
There is also this log in the stack trace.
Survey+c__Iterator0.MoveNext () (at Assets/Survey/Survey.cs:76)
The stack trace you have posted is read from bottom to top so if we look at the first entry of UnityEngine.EventSystems.EventSystem:Update() this would suggest that eventsystem runs an update function periodically and dies when it hits your survey script. I would imagine this is because your survey script does not initially have the data it is looking for, hence the out of range exception, before the update function runs in eventSystem. I am not too familiar with this so I will need to google, but hopefully this might help you look in the right direction.
The function at the very top of the stack is the last place the error affects and is the most core functionality of the environment which is probably why you cant find information on it. I always try to find references to my own code in stack traces as its most likely to be wrong.
I would do a test to see if you disable your survey script does this error go away, this will at least show that it is in fact an error you can control, Instead of some bug with unity/google.
Answer by dm_bond · Oct 24, 2018 at 11:06 PM
https://github.com/Unity-Technologies/UnityCsReference/blob/2018.1/Modules/UnityWebRequest/Public/WebRequestUtils.cs#L505 You need to check yourself (!string.IsNullOrEmpty) before pass url to WWW or UnityWebRequest in 2018.1