How to launch Retroarch from frontend made in Unity

Hi! I’d like to know if it’s possible to load a game in Retroarch’s Genesis Plus GX core on Android, passing a few arguments (touch input disabled, a certain physical gamepad layout, optional saved game path to load, and CRT shader option) from a frontend made in Unity. I started it for fun (based on the Mega Drive) and now I’d actually like to try to launch a game and maybe finishing it.

If someone could at least point me in the right direction about this, I’d really appreciate it :slight_smile: I wouldn’t precisely need to know how to do it from an Unity application. A generic method for any Android frontend would be more than enough.

Thanks in advance.

This should cover most of it: http://www.vogella.com/tutorials/AndroidIntent/article.html

Most of the things you described aren’t accessible with command line switches but you could put them into a config file and then use the -c switch to point to the correct file.

So all I’d need to do is finding how to use intent in Unity, then preparing a retroarch config file generator (with all the parameters I need everytime I launch a game), and try to launch retroarch with the -c parameter to load this config file, from my Unity app.

Sounds good! I’ll share here any useful info I find.

Ok, so far so good. I learnt how to launch any app from Unity and then how to launch Retroarch. Now I’m trying to load Genesis Plus GX core and a file I have located in a known and confirmed path, but can’t load the rom, and not sure if at least the core is loaded. I’m saving the CONFIGFILE and IME options for later, once I’ve got a rom working, but I don’t know if they should be set in order for the rom to load.

Here’s my code (grabbed from some unfinished examples from the Unity forums). I’d appreciate if someone could take a look and let me know if there’s something wrong:

	public void LaunchApp() {
	if (Application.platform == RuntimePlatform.Android) {
		bool fail = false;

		string bundleId = "com.retroarch";
		string fileName = Application.persistentDataPath + "/Aladdin.smd";
		Debug.Log ("ROM PATH: " + fileName); // I print this to confirm the path is correct

		// the next four lines don't need to be changed
		AndroidJavaClass up = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
		AndroidJavaObject ca = up.GetStatic<AndroidJavaObject>("currentActivity");
		AndroidJavaObject packageManager = ca.Call<AndroidJavaObject>("getPackageManager");
		AndroidJavaObject launchIntent = null;

		try {
			launchIntent = packageManager.Call<AndroidJavaObject>("getLaunchIntentForPackage", bundleId);
			launchIntent.Call<AndroidJavaObject>("putExtra", "ROM", fileName);
			launchIntent.Call<AndroidJavaObject>("putExtra", "LIBRETRO", "/data/data/com.retroarch/cores/genesis_plus_gx_libretro_android.so");
			//launchIntent.Call<AndroidJavaObject>("putExtra", "CONFIGFILE", getRetroarchProperties);
			//launchIntent.Call<AndroidJavaObject>("putExtra", "IME", ime);
		}
		catch (System.Exception e) {
			fail = true;
		}

		if (fail) {
			Debug.Log("App not found");
		} else {
			ca.Call("startActivity", launchIntent);
		}

		up.Dispose();
		ca.Dispose();
		packageManager.Dispose();
		launchIntent.Dispose();
	}
}

}

Are you getting any errors from RetroArch printed to the log?

Nothing on screen, I’m afraid. I guess there’s a log file but, where would it be located?

Thanks, by the way :slight_smile:

EDIT: checked the Android Device Monitor. No error message as well. It’s like it was totally ignored.

RetroArch prints all of its messages to the regular Android logging stream, so you’ll need to use a logcat app or adb logcat to view them.

I did see Retroarch’s messages in the Android Device Monitor, just no error message, and nothing related to the rom or core parameters. Like they didn’t reach to Retroarch’s intent.

I’m thinking that the problem has to be that I’m passing a rom that’s in the frontend’s private directory. I’m investigating how to read the roms from a public directory. Will get back when I find a solution.

No luck. I managed to make my frontend read the roms paths from a directory in /storage/emulated/0/MyFrontend/Games. I check the rom exists before sending it to Retroarch through putExtra, but Retroarch just goes to main menu.

This is Android 7.0, by the way. Not sure if there’s something else I should add.

Hmm, yeah, I guess it could be related to permissions, though RetroArch doesn’t usually have any problem reading content from any directory.

I tried launching another app using “putExtra”, just to be sure I’m doing everything alright, and it worked. I wonder if I could just use the CONFIGFILE extra parameter to load the rom and the core. Would that be possible?

Yeah, that’s worth a shot.

i wish any of the existing frontends that use the intent for launching were open source, so you could just see how they’re doing it…

Yeah, I was surprised there is no example at all anywhere :frowning:

Hmmm… Apparently the core file doesn’t exist but the cores directory does. I’ll check where this core is located (got that text from a post somewhere, but never checked the core location).

Nothing again. I changed the cores location to a known path. My frontend now detects both the cores path and the genesis plus gx core exist, but Retroarch does nothing.

Guess I’ll have to try to reach a frontend developer for help.

Still no luck lunching Retroarch in Unity?

Still no luck lunching Retroarch in Unity?

I’m afraid not :frowning: I abandoned Android a moved to Linux. At least I can figure out how to make it work.