- Home /
AndroidJavaClass Won't initialize in Start()
I've come across something unusual in my unity project, I'm using AndroidJavaClass to access some static methods in an Android plugin i made.
My wrapper class looks like this:
private AndroidJavaClass AJCplugin;
void Start() {
AJCplugin = new AndroidJavaClass("com.auth.cdbr3d.bitworks.BitmapManipulator");
}
public string Test() {
if ( AJCplugin != null ) {
return AJCpluign.CallStatic<string>("TestMethod", "WORKING");
}
else {
return "AJC is null";
}
}
When the class is configured this way, AJCplugin is always null.
However, if i move things around so its like this:
private AndroidJavaClass AJCplugin;
bool bl = true;
public string TestInterface() {
if ( bl ) {
AJCplugin = new AndroidJavaClass( "com.auth.cdbr3d.bitworks.BitmapManipulator" );
bl = false;
}
if ( AJCplugin != null ) {
return AJCplugin.CallStatic<string>("TestMethod", "WORKING");
}
else {
return "AJC is null";
}
}
The AJCplugin is never null, even though I'm only assigning it once in both configurations, it seems it never gets assigned if it's initialized from Start()
or Awake()
It isn't the end of the world and the application can likely continue to function as normal, but I'm mostly curious as to why this is behaving this way, and if it is normal behavior.
is this class inherited from $$anonymous$$onoBehaviour? if yes, is it on a scene object?
It does, and it wasn't, i found that adding it to a scene object made it work. I assume that in order for things that inherit from $$anonymous$$onoBehaviour
to work as expected they need to be present and active in the scene?
Exactly. The $$anonymous$$onoBehaviour inherited classes should be on scene or it's $$anonymous$$onoBehaviour dependent methods will be ignored.
Ahh thank you, ill go ahead and mark it as answered then!