Call StartCoroutine() from inside a function other than Start!?

I have a class DBConn, which have 2 functions JoystickFound() and GetData():

public void JoystickFound(string JoystickName)
	print ("Qr Found : "+JoystickName);
IEnumerator GetData(string JoystickName)
	WWWForm sendJoystickInfo = new WWWForm();
	WWW getdata = new WWW(GetUrlsPhp,sendJoystickInfo );
	yield return getdata;
	string[] split = getdata.text.Split("|"[0]);
	JoystickName   = split[0];
	ProfileName  = split[1];
	LevellName = split[2];

When I run the project, i see an error that the StartCoroutine function should be called from Start function, when I do it it works perfectly.
However, I need to be able to run this function from inside a function Joystick Found, and not from start, any idea how to do that?

You can use StartCoroutine in any function, as long as the class derives from MonoBehaviour.

There is no requirement that StartCoroutine has to be called from Start, but it has to be called from the main thread. So it depends who’s calling the JoystickFound method. If it’s some kind of callback from a plugin it’s probably invoked from another thread. In this case you might want to use something like the Loom class at the bottom of the article to schedule the method on the mainthread.

There’s no way around this. The whole Unity API is not thread-safe and does only work when used from the main thread.

ps: without seeing the whole picture we can’t say where you did something wrong.