Is there a Godot equivalent to Unity's AndroidJavaObject?

Godot Version

4.2

Question

I’m migrating from Unity over to Godot. I’m making an Godot-Android plugin to use custom Android services. I’m trying to avoid writing a single class with 500 methods to access all the Android features I need to interact with. It would be ideal to pass a reference to Godot Engine of a Java class and use that reference to call from Godot scripts into Android.

The idea is to organize the methods by class, and have a Godot script that interfaces with the java class. So graphic calls can go to the graphics java object reference, and game-state calls can go to the game-state java object.

Within Unity this can be done by getting a reference to an AndroidJavaObject. That reference then gives access to the Java methods of that class.

Within Godot, making an AndroidPlugin will provide a singleton that gives access to methods defined in the class that extends GodotPlugin with the @UsedByGodot tag. I’m hoping that I could define, getGraphicsClass() in Java that returns a reference to MyGraphics, that within Godot Scripts, I can call into that reference outside of the GodotPlugin singleton.

Again, this is to help organize all the method calls I want.

I found the answer to my question. It is possible to define multiple plugin-ins within the same Android aar. Within the manifest, you can add a meta-data tags for each plugin.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

	<application>
		<meta-data
			android:name="org.godotengine.plugin.v2.PluginOne"
			android:value="com.pixelcube.godot.plugin.PluginOne"
			/>
		<meta-data
			android:name="org.godotengine.plugin.v2.PluginTwo"
			android:value="com.pixelcube.godot.plugin.PluginTwo"
			/>
	</application>
</manifest>

Then for each tag, have a Java class to extend GodotPlugin. Within GodotScripts, you can access each module (plugin) individually and that will help organize the method calls to related methods and Android modules.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.