0
votes

here I have exported project and created an aar file and imported in the android studio and my android studio simply passes an intent to unity player activity on a button click. but I keep getting the game object as null. What could be the problem? this doesn't even work when I set the object manually and set it to true and run in unity only.. it doesn't even print debug.log();

Here i am using vuforia ground plane detection and my object is kitchen stool and i am placing it inside ground plane stage. and the script is in ar camera.

    using System.Collections;
using System.Collections.Generic;
using UnityEngine;

     public class data : MonoBehaviour
{
   // private Transform childObj;
    // Start is called before the first frame update
    void Start()
    {
        AndroidJavaClass UnityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject currentActivity = UnityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
        AndroidJavaObject intent = currentActivity.Call<AndroidJavaObject>("getIntent");
        bool hasExtra = intent.Call<bool>("hasExtra", "arguments");
        if (hasExtra)
        {
          AndroidJavaObject extras = intent.Call<AndroidJavaObject>("getExtras");
         string arguments = extras.Call<string>("getString", "arguments");
         GameObject g = GameObject.Find(arguments);
         g.SetActive(true);
         Debug.Log("hello");
         }

    }

    // Update is called once per frame
    void Update()
    {
    }
}
1

1 Answers

1
votes

You cannot use .Find() to find a gameobject that is inactive in your scene. You can either assign the object up front in the inspector or use Resources.FindObjectsOfTypeAll. Alternatively, make the object the child of an empty gameobject, and use transform.GetChild(0) to toggle its state.