Problem with ILocationService Instance

Include the following details (edit as applicable):

  • Issue category: VPS
  • Device type & OS version: Android
  • Host machine & OS version: Windows
  • Issue Environment : On Device

Description of the issue:

Hello,

When I start a WayspotAnchorService with a referenced ILocationService that I created in another script beforeHand, the WayspotAnchorService is created without any error, but the localization failed with the message " LocationDataNotAvailable", even if the location service is running and returning data.

The only way I can make the localization process work is if the ILocationService is created and started just before creating the WayspotAnchorService.

Why ? Is it normal ? Am I missing something ?

Thank’s in advance for any answers …

Hi Nicolas,

Localization can fail for a variety of reasons, and you can check the LocalizationFailureReason in a callback method that’s assigned to listen to the WayspotAnchorController.LocalizationStateUpdated event. More information on Localization Failures & Recovery Steps can be found in the Lightship documentation here.

It sounds to me like you may be experiencing a LocalizationFailureReason of LocationDataNotAvailable, but it will be worth it to verify the failure reason on your end first to better diagnose the issue.

Additionally, it may be the case that the ILocationService is being initialized in the other script later (at run-time) than the WayspotAnchorController, especially if the two initializations are occurring in the same Unity lifecycle event (i.e. Awake(), Start(), etc.), but on separate objects. If you want finer control over the order of which scripts execute their Unity lifecycle events first, you can manually alter Unity’s script execution order by navigating to Edit > Project Settings > Script Execution Order – to ensure the script containing your ILocationService initialization is ran prior to the script containing the WayspotAnchorService initialization. This may help solve the issue if the initialization of each service is occurring in a separate script but in the same Unity lifecycle event, such as Awake(). More information on altering script execution order in Unity can be found in the Unity manual here.

Hi Rob,

Thanks for the answer, my LocalizationFailureReason is indeed “LocationDataNotAvailable”. I didn’t know that unity made it possible to manually alter script execution order so thank you for this information. But for me this is not the issue, my ILocationService is created way before my WayspotAnchorService and of course, I check that my ILocationService did exist before creating a WayspotAnchorService.

To be more precise, if I try to access an ILocationService instance created beforehand in another script where I create my WayspotAnchorService, the WayspotService is created successfully but never managed to localize because of the failure reason “LocationDataNotAvailable”, even if my LocationService retrieves data before the creation of the wayspotService.

But if I create a new ILocationService in the same script that I create my WayspotService, it localizes successfully but I now have to ILocationService running at the same time and that bothered me.

We attempted to reproduce the issue by creating an ILocationService in one script via LocationServiceFactory.Create(), and using it as a parameter for creating a WayspotAnchorService in a second script. However, the scene functioned as expected and did not produce a localization failure state.

Can you either share any relevant script files, or include some code snippets for us to examine? It sounds like the location service being used when creating the wayspot anchor service instance may not be referencing the same location service that was created in the other script, but it’s difficult to assess without being able to examine the code.

Here are my code samples (sorry for the bad code quality I’m a beginner) :

-First, I create my Instantiate my LocationService (which contains the ILocationService reference) and reference it on a variable.
image
image

  • Then, later on, I create my WayspotService (I indicate which line work and which creates the NoLocationDataAvailable failure).

Some precisions; I forgot to tell you that in the mock environment it doesn’t create any failure reason, it’s only on the live device environment.

Thank you in advance for the time you take, and sorry if its only my bad code that create the bug