Select to view content in your preferred language

API request isn't working in Unity

640
9
08-26-2024 06:40 AM
JustinCresta
New Contributor

Hello,

I'm using Unity 2022.3.42f and ArcGIS Maps SDK for Unity version 1.6.0.

I'm trying to follow the tutorial here: https://developers.arcgis.com/unity/maps/tutorials/display-a-map-api/ 

I have an API key, as shown in the first image. I have all the code copied. Both the map component and the camera are successfully created, but the map itself doesn't show. The inspector for the map component doesn't show the basemap, elevation, or layers either, as shown in the second image.

I have also tried using the map creator UI and samples and gotten similar results, making me inclined to believe that the issue is with my API key or request. When I check the developer credentials, it also says that the API key has had no usage.

Thanks for the help, sorry if this post was silly.

0 Kudos
9 Replies
HadidIgis
New Contributor

I am having the same issue, were you able to solve it?

0 Kudos
AShahbaz
Esri Contributor

Hello,

  • Can you confirm that you have attached the created script to an empty game object (or an existing game object)?
  • Can you load any of the sample scenes with your API key?
  • Could you add a View State Logger to the map game object and monitor the console for any errors or warnings? (you may need to import the plugin samples if you haven't done yet)
0 Kudos
AnirudhJ
Emerging Contributor

Hi, I am having the same issue when using the map creator UI (I have not tried the API method). I can confirm I cannot load any of the sample scenes: I am getting a "no viewport" error in every case. 

The following link tells me that means "there is not a valid camera, viewport properties, or spatial reference" but I fail to see how that can be the case even in the samples.

ArcGISViewStatus | ArcGIS Maps SDK for Unity | Esri Developer

0 Kudos
AShahbaz
Esri Contributor

Are you loading the sample scenes individually or through the Sample Viewer UI? How do you set the API key (project settings, ArcGISMap Actor, or Sample Viewer UI)?

0 Kudos
AnirudhJ
Emerging Contributor

I am loading the sample scenes through Unity individually, by double-clicking on each scene.

I set the API key by clicking on the ArcGISMap GameObject that gets created and setting the API key there. I have also tried setting the API key in the Map Creator UI panel: 

Screenshot 2024-10-10 113235.png

In every case I am getting the same error, with no map data being loaded: 

AnirudhJ_0-1728540328449.png

 

0 Kudos
AnirudhJ
Emerging Contributor

Hi, sorry for the ping. I am still facing the same issue - the map does not load even now. What options can I try to get it to work?

AnirudhJ_0-1728894672136.png

 

In every case I am getting the same error, with no map data being loaded: 

AnirudhJ_1-1728894672096.png

 

 

0 Kudos
AShahbaz
Esri Contributor

Hi, it is a bit difficult to tell what is going on since loading the sample scenes should definitely work, here are a few ideas to debug the issue:

  • I'd try playing the sample viewer scene (under "Assets/SampleViewer/SampleViewer.unity" ) and entering the API key in the UI there before picking a scene from the list
  • Could you confirm that you are using the latest plugin version (1.6) and the current Samples project? What Unity version are you using?
  • Is there any error messages related to the plugin when you open Unity (beside the warnings from `ArcGISViewState`). If so, please remove the plugin and reload it from tarball or asset store
  • Please reload the built-in sample content (in the package manager window click on the plugin, open the Sample tab and click Reimport). Test to see if those samples work (e.g., "Assets/Samples/ArcGIS Maps SDK for Unity/1.6.0/Sample Content/Scenes/HDRP/ComponentLocal.unity")
  • Verify that the API key works with any other Esri services. You could for example attach your API key at the end of the following URL and open it in a browser: `https://basemaps-api.arcgis.com/arcgis/rest/services/styles/ArcGIS:Navigation?token=`. If there is no issue with the API key, you should see a long json text, otherwise there will be an error message. 
0 Kudos
AnirudhJ
Emerging Contributor

Hi, thank you for the reply. I tried verifying whether the API key still works and I got error 498. Apparently this means the access token is expired or invalid? I regenerated the token by going to my token credentials and found that the new regenerated key is working.

The API key was not supposed to expire for two more weeks. I set the expiration date of the newly regenerated key to be at the end of 2024 for now. Is there a reason why the key expired prematurely? How can I prevent this happening for future keys?

0 Kudos
AShahbaz
Esri Contributor

Glad it is working now. I am not sure why the API key would expire. It shouldn't have happened. If this happens again, please let us know (possibly in the general developers community)

0 Kudos