2

I'm developing an Android app and I need to integrate Unity games/screens in it. I've already exported and added one Unity scene/project to my android app but I cannot figure out how to add two.

I found two main approaches to this:

  1. Create two separate projects: If I do this they clash either in the manifest or in the libraries/assets folder and unity ends up calling just one scene. For reference:

How to correctly import multiple unity module in single android app avoiding name conflict between different unity module in android studio?

  1. I also tried creating one Unity project with multiple scenes and use messages to call the required scene from Android. For me, Android still calls the same scene regardless of which button is pressed. Reference: https://stackoverflow.com/a/43224821/2617578

Does anyone have a solution for this? Either one of the solutions mentioned above would be okay for me.

I'm experienced in Android but a beginner in Unity so I think I might be doing something wrong in the unity code.

I have the unity projects and Android apps I created for the second approach in the following git repository.

https://github.com/hadi-mehmood/AndroidUnityIntegrationSample

1
  • If you added one Unity project to android then I think Method 2 should work. are you able to run both scenes in the unity project? (not from android but in the unity editor) Commented Sep 29, 2019 at 18:11

1 Answer 1

2
+50

Here is one solution to your problem:

First, All things happen inside unity are in one activity.

  • Combine two unity projects and make different scenes for each of them
  • create a empty loading scene that starts first (using unity BuildSettings) and does not do anything
  • on the loading scene, write a SceneLoader script to wait for a command to load a minigame scene.
  • you can pass the scene name using this method UnityPlayer. UnitySendMessage("Gameobject Name","Method","Message")
  • right after running Unity Activity call the method above and it should do the work.

Sample SceneLoader:

public class MySceneLoader : MonoBehaviour
{

    private void LoadScene(string sceneName)
    {
        SceneManager.LoadScene(sceneName);
    }
}
1
  • 1
    Hi Amin, I had done the exact same thing. The only problem in my code was that the name of the untiy object was different to what I was sending in the UnitySendMessage function. Thank you for pointers! Edit: It stops me from awarding the bounty right now, will do so once it does.
    – Hadi
    Commented Sep 30, 2019 at 9:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.