Search Unity

[SOLVED] GameObject.Find not working on Android!?!

Discussion in 'Scripting' started by varunvp, Oct 21, 2016.

  1. varunvp

    varunvp

    Joined:
    Jul 11, 2014
    Posts:
    57
    Hey guys,
    I have some scripts, in which the Start() contains some important variables which are initialised by using Gameobject.Find(). It happens perfectly in the editor, but when I deploy on mobile, it does not work as expected. All the errors point to the Find() lines, when I checked in the adb logcat. What could be wrong???
     
  2. varunvp

    varunvp

    Joined:
    Jul 11, 2014
    Posts:
    57
    Does it have to do something with the scene not being fully loaded on Android, since I am using Async loading?
     
  3. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,187
    I haven't used async loading myself, but you could try using log viewer
    https://www.assetstore.unity3d.com/en/#!/content/12047
    which is free and basically lets you see your console on a build on tablets. Logcat is a great tool, but I find log viewer is a good first step to tracking down what might be going on.

    When you say it's not working as expected, is it just returning null and thus not finding anything? Or is it something else?
     
    varunvp likes this.
  4. varunvp

    varunvp

    Joined:
    Jul 11, 2014
    Posts:
    57
    It throws NullReferenceException. Can it be from incomplete loading of the scene?
    I will try that plug in though. Thanks!
     
    Last edited: Oct 21, 2016
  5. varunvp

    varunvp

    Joined:
    Jul 11, 2014
    Posts:
    57
    Hmmmm, well I tried that plug-in, it proved the same thing again. Instead of using Gameobject.Find, i used another 3rd party tool to find the gameobjects, but it seems even it has trouble to find the gameobjects! This is what I used
    https://www.assetstore.unity3d.com/en/#!/content/27962
    I am now going to try just loading the scene directly, not with async.
     
  6. Rob21894

    Rob21894

    Joined:
    Nov 21, 2013
    Posts:
    309
    Try putting the Gameobject.Find functions in Void Awake()

    See if this changes anything
     
  7. varunvp

    varunvp

    Joined:
    Jul 11, 2014
    Posts:
    57
    I later realised that some of my objects were tagged as EditorOnly. Made them untagged, still the same problem.

    I will try this now, although I doubt it will change anything.
     
  8. varunvp

    varunvp

    Joined:
    Jul 11, 2014
    Posts:
    57
    Nope, this did not fix it.
     
  9. varunvp

    varunvp

    Joined:
    Jul 11, 2014
    Posts:
    57
    OK, solved it. The GameObjects I wanted to find were parented under a gameObject which was tagged 'EditorOnly'. Damn oversight. Also, if it were not for a random article I read yesterday, wouldn't know that objects tagged EditorOnly are excluded in the build. Phew!
     
  10. fangye_Studio

    fangye_Studio

    Joined:
    Nov 19, 2012
    Posts:
    26
    I met the same problem, but the tag is default "Player" , cant find by tag in awake() on android platform