Select to view content in your preferred language

Unable to find a parent ArcGISMapComponent (UnityEngine LogError)

57
0
Friday
ZacharyNelson1
New Contributor

Hi, I'm trying to map some features I have saved in a geoJSON file using the ArcGISMaps SDK for Unity. My game object hierarchy is simple at the moment and contains an ArcGISMap (with ArcGISMapComponent script attached), ArcGISCamera (a child of the ArcGISMap), and an empty game object containing a "LoadGeoJSON" script.  The empty game object also contains a sphere prefab child. This is kind of a placemark that I'm trying to mark the coordinates with on the ArcGISMap.

My features are getting mapped to the desired coordinates in the console display but I'm getting an "Unable to find parent ArcGISMapComponent" error in the console as well when running the app in Unity. Might be helpful if I provide some code from my loader script:

using UnityEngine;
using System.IO;
using Esri.GameEngine.Geometry;
using Esri.ArcGISMapsSDK.Components;
using Newtonsoft.Json.Linq;
using System.Collections;

public class GeoJSONLoader : MonoBehaviour
{
public string geoJSONFilePath = @"placeholder for the file path";
public GameObject pointPrefab;

private float defaultAltitude = 25.0f;
private ArcGISMapComponent arcGISMapComponent;

void Start()
{
arcGISMapComponent = FindAnyObjectByType<ArcGISMapComponent>();
LoadGeoJSON();
}

private void LoadGeoJSON()
{
string geoJSONText = File.ReadAllText(geoJSONFilePath);
JObject geoJSONData = JObject.Parse(geoJSONText);

foreach (var feature in geoJSONData["features"])
{
var coordinates = feature["geometry"]["coordinates"];
double lon = (double)coordinates[0];
double lat = (double)coordinates[1];

PlaceMarker(lat, lon);
}
}

private void PlaceMarker(double latitude, double longitude)
{
GameObject marker = pointPrefab ? Instantiate(pointPrefab) : GameObject.CreatePrimitive(PrimitiveType.Sphere);
marker.transform.localScale = Vector3.one * 5.0f;

var locationComponent = marker.AddComponent<ArcGISLocationComponent>();
locationComponent.Position = new ArcGISPoint(longitude, latitude, defaultAltitude, ArcGISSpatialReference.WGS84());

marker.transform.SetParent(arcGISMapComponent.transform, true);

Debug.Log($"Placed marker at latitude: {latitude}, longitude: {longitude}, altitude: {defaultAltitude}");
}
}

Anyone know how to solve this problem? Maybe I'm not parenting the location component correctly?

0 Kudos
0 Replies