Question

I have a native Android service running in the background that needs to interface with a Unity3D script. I'm aware of the following method:

com.unity3d.player.UnityPlayer.UnitySendMessage(String gameObject, String arg1, String arg2)

But it requires a gameObject parameter. Since the service is running in the background, I can't be 100% sure that a gameObject attached to a particular scene has not yet been destroyed. Is this a fair assumption (since the user might not even be in the app)?

If so, is there a way to instantiate a gameObject that is never destroyed? Is there any other way to call a unity script from native Java code?

Was it helpful?

Solution

I do not know about how to call unityscript from native code. But you can make a GameObject stay alive until manual removal by using the DontDestroyOnLoad function on it. Example:

void Awake() 
{
    DontDestroyOnLoad(transform.gameObject);
}

More info from here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top