Search Unity

Question Geo Fencing not working on physical device

Discussion in 'Unity MARS' started by MatWright, Jun 5, 2021.

  1. MatWright

    MatWright

    Joined:
    Jun 20, 2019
    Posts:
    7
    Hi,

    I am using a Geo Fencing condition.

    I initially spawn an unlimited number of Horizontal Planes with a Synthetic Object component attached including a semantic tag.

    I then instantiate a Prefab multiple time at runtime based on data from a database.

    Each instantiated object has its own BoundaryBox specified with a unique lat/long.

    The lat/long are set to five decimal places. The lat/long extents are set to 1e-04

    This all works fine in the simulator using my current gps position as the simulated center.

    However it is not working when deployed to a physical device : Android 11, Pixel 3 XL

    I have tried with different Extents.

    For info, I am requesting permission for FineLocation. This part appears to be working as I am able to print my device's lat/long to the screen.

    But, no geofenced objects are appearing at all.

    When I remove the geofence condition, the objects are spawned correctly.

    I have experimented with having the condition disabled and then enabling it at runtime once it is configured as per advice I saw in an older thread.

    I am working with Unity 2020.3.11f1

    Any help much appreciated!
     
    Last edited: Jun 5, 2021
  2. MatWright

    MatWright

    Joined:
    Jun 20, 2019
    Posts:
    7
    upload_2021-6-5_12-38-20.png

    My settings.
     
  3. MatWright

    MatWright

    Joined:
    Jun 20, 2019
    Posts:
    7
    Code (CSharp):
    1.   var geoFenceCondition = myPrefab.GetComponent<GeoFenceCondition>();
    2.  
    3.         var boundingBox= new GeographicBoundingBox
    4.         {
    5.             center = new GeographicCoordinate(46.34040,5.07097),
    6.             latitudeExtents = 1e-04,
    7.             longitudeExtents = 1e-04,
    8.         };
    9.  
    10.         geoFenceCondition.BoundingBox=boundingBox;
    Example of how I am configuring a boundingbox
     
  4. thomas_key

    thomas_key

    Unity Technologies

    Joined:
    Dec 14, 2019
    Posts:
    39
    You should use the
    SyncModifications()
    method of Proxy / ProxyGroup after making these sorts of code changes to proxy conditions.

    Why this is needed is that the db has it's own copies of the various condition data stored in a more optimal format, and the condition checking runs on a background thread for performance. With the inspector, syncing this data is handled automatically. When making changes at runtime however, it's necessary to manually notify the system a proxy (or proxy group) has changes applied to it. Calling SyncModifications() informs the query db of a change and schedules a "modification" change action. A modification change can take a few frames to get picked up, as the db query scheduling thread is synced intermittently with the main thread via an actions buffer.

    - https://docs.unity3d.com/Packages/c...Proxy.html#Unity_MARS_Proxy_SyncModifications
    - https://docs.unity3d.com/Packages/c..._ProxyGroup_SyncModifications_System_Boolean_
     
  5. MatWright

    MatWright

    Joined:
    Jun 20, 2019
    Posts:
    7
    Thanks for your help @thomas_key

    Calling SyncModifications() still doesn't help my geofenced Proxies to spawn unfortunately.

    Just to be clear, I am creating the proxies at runtime; I am not merely configuring existing proxy instances. As such
    I wouldn't have thought any data will have been saved to the DB in my case, prior to adding the geo based condition.

    To be clear, I have a replicator configured to spawn unlimited horizontal plane proxies. Each one has a Synthetic Object with a synthesized tag.

    Then, at runtime, I instantiate Proxy objects from a prefab. These proxies have a Semantic Tag condition referencing the above mentioned tag. These runtime proxies are the ones which also have a Geo condition configured based on live data from an external database.

    When I remove the Geo condition component, they appear fine. When the Geo condition is active they do not appear at all. The Geo condition itself is correct; and the objects do appear in simulation mode using the same lat/long as my physical device.

    I am at a loss as to why the geo condition is not being met when the app is deployed to a physical device.

    I have manually requested permission for fine location perms and I can print the devices lat.long to the screen; so that doesn't appear to be the cause either.
     
    Last edited: Jun 8, 2021
  6. CiaranWills

    CiaranWills

    Unity Technologies

    Joined:
    Apr 24, 2020
    Posts:
    199
    I think the problem here is that MARS's geolocation service doesn't start automatically by default. You can turn it on in the project settings:

    upload_2021-6-8_16-32-51.png

    Let us know if this doesn't get things going.
     

    Attached Files:

  7. MatWright

    MatWright

    Joined:
    Jun 20, 2019
    Posts:
    7
    Thanks @CiaranWills I did have this option turned on; so this wasn't the issue.
    The solution provided by @thomas_key does seemed to have worked in the end.
    My initial tests weren't conclusive but I found other factors had crept in from making so many changes/tests.
    So, thanks for all the help; I have this working now.

    Mat
     
    thomas_key likes this.