Select to view content in your preferred language

Errors with attaching script components from ArcGIS Maps SDK for Unity

757
2
03-06-2024 09:26 AM
OwenGebhardt
Emerging Contributor

Hello! I'm working on a Unity project using the ArcGIS Maps SDK, and it was working fine when I signed out of my work computer yesterday, but is now throwing errors which I believe are related to loading the component scripts that come with the SDK.

I primarily followed the Display a map (C# API) ArcGIS Developers tutorial to get the code for displaying the map, and modified the code slightly to display my own building feature layer. The program used to display the buildings both while playing and in the editor, but now only displays in the editor.

Both while playing and in the editor, the program throws errors. Upon loading the scene in the editor or just returning to the editor by stopping the project, a NullReferenceException is thrown. Hitting the play button throws that same NullReferenceException and a number of warnings just saying "The referenced script (Unknown) on this Behavior is missing!"

PlayingErrors.PNG

The full error for the NullReferenceException is:

 

NullReferenceException: Object reference not set to an instance of an object
Esri.ArcGISMapsSDK.Components.ArcGISEditorCameraComponent.set_EditorViewEnabled (System.Boolean value) (at ./Library/PackageCache/com.esri.arcgis-maps-sdk@4daa00a77df6/SDK/Components/ArcGISEditorCameraComponent.cs:72)
Esri.ArcGISMapsSDK.Components.ArcGISMapComponent.OnEnable () (at ./Library/PackageCache/com.esri.arcgis-maps-sdk@4daa00a77df6/SDK/Components/ArcGISMapComponent.cs:678)

 

The Main Camera now has extra "(Script)" components that seem to have not loaded properly, and I believe they're the cause of the missing script warnings that appear when playing the project. ("RIT Scene" is the script I wrote based on the tutorial.)

CameraInspector.PNG

Unity also throws a message in addition to the usual NullReferenceException when I first open the project after reverting to my Git commit from yesterday:

 

Can't add 'ArcGISCameraControllerComponent' to Main Camera because a 'ArcGISCameraControllerComponent' is already added to the game object!

 

Errors1.PNG

I also tried using the component-based workflow from the Display a map (Components) ArcGIS Developers tutorial, but ran into a roadblock when the ArcGIS Camera component refused to be added to the Main Camera object. It presents an error box saying "Can't add script component 'ArcGISCameraComponent' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match." I think this may be a clue as to the underlying problem, suggesting the components weren't imported correctly or aren't being referenced correctly. That said, I don't know why the script-based workflow still seemingly locates them properly while the project is playing when the Unity editor itself can't.

Errors4.PNG

I'm using Unity Editor version 2022.3.4f1 and Maps SDK version 1.4.0, which I imported from the .tgz available for download on the Esri website. I'm also using GitHub for version control.

If you can help me diagnose the problem and get the map displaying consistently in both the player and the editor, I would appreciate it very much!

0 Kudos
2 Replies
and1
by Esri Contributor
Esri Contributor

Not sure if there is anything related to your script, but it seems like there are some repetitive/missing components on the MainCamrea from your screenshots. If your "RITScene" script is based on the C# API tutorial, it should automatically add all those necessary camera components to your MainCamera gameobject once you enter the Play mode. You don't need to manually add those components as the script is already handling it. So I would first try to manually deleting all those redundant components from the inspector and only keep your "RITScene" along with your other custom scripts (weather, etc.) you might have as the screenshots below:

and1_0-1711057290492.png

Then enter the Play mode, now you'll notice that the script will load all those camera related components:

and1_1-1711057414354.png

Give a quick try and see if this works.

 

 

 

0 Kudos
OwenGebhardt
Emerging Contributor

Just tried this; I deleted all ArcGIS-related components from the main camera, including HPTransform and my RITScene component (which I have since renamed to ArcGISScene after some refactoring), then unparented it from the ArcGISMap object so I could delete that too. I then added the ArcGISScene component back onto the camera and ran the scene so it could regenerate its various ArcGIS components. Unfortunately the same error still shows up. Like before, the map works just fine when the project is running, but when I stop the project the map doesn't show up in the editor despite having the [ExecuteAlways] attribute at the top of ArcGISScene.cs.

CameraAfterRegenerating.PNG

I also noticed a few differences between our screenshots of the inspector for the main camera. My ArcGIS Camera and Rebase both always appear disabled, and clicking the checkbox to enable them doesn't appear to actually tick the box. Also, when I right-click either of them and select "Edit Script," then instead of opening it in my IDE like it does with my own scripts and other ArcGIS ones, it just opens this blank "(Mono Script)" window in the Inspector:

InspectorRebaseEditScript.PNG

I'll bet that has something to do with the issue, since the line in ArcGISEditorCameraComponent.cs that creates the error is calling GetComponent<ArcGISCameraComponent>()... but I do wonder what could be stopping the scripts from loading, and how we could fix it.

Either way, thank you for your response!

 

 

0 Kudos