Topic: Null Error on AddMarker
I am using multiple scripts to access the map and originally I had the map/marker definition in each script as private, but when I did a OnMarkerClick there appeared to be7 bleed over between the scripts. I could tell this because each script added a different colored marker teture but when I clicked a specific color it waould use code from a differnt script. Hopefully this is somewhat clear.
What I did was move all the map code to one script and access this using an Instance of that script MapControls.Instance.SetMarkers... for example.
Now when I use one script to call the other to do an AddMarker, I get a Null Error. I have debugs that show all the fields contain the right data so not sure what is goin on. Below is the error then the code including debug results:
========== Error Begin
NullReferenceException: Object reference not set to an instance of an object
MapControls.SwitchFunctions (System.String func) (at Assets/_Scripts/MapControls.cs:148)
MapControls.Awake () (at Assets/_Scripts/MapControls.cs:59)
========== Error End
========== MapControls Script Code
Map/Marker Definition:
private OnlineMaps map;
private OnlineMapsMarker marker;
Add Markers Script:
public void SetMarkers(double tempLng, double tempLat, Texture2D tempTex, string tempLabel) {
Debug.Log(" ");
Debug.Log("SetMarkers - lng: " + tempLng + " lat: " + tempLat);
Debug.Log("SetMarkers - Texture: " + tempTex.name);
Debug.Log("SetMarkers - Label: " + tempLabel);
//// Actual Debug Results:
SetMarkers - lng: -120.071841 lat: 39.26079
SetMarkers - Texture: MarkerTextures_Blue
SetMarkers - Label: Hwy 267 at Brockway Summit
////
map.AddMarker(tempLng, tempLat, tempTex, tempLabel);
}
========== End Of MapControls Script Code
========== Calling Script Code
double tempLng = double.Parse(tempRow.longitude.ToString());
double tempLat = double.Parse(tempRow.latitude.ToString());
Debug.Log("LoadCADistrict - lng: " + tempLng + " lat: " + tempLat);
Debug.Log("LoadCADistrict - Texture: " + markerTexture.name);
Debug.Log("LoadCADistrict - Label: " + tempRow.locationName);
//// Actual Debug Results:
LoadCADistrict - lng: -120.071841 lat: 39.26079
LoadCADistrict - Texture: MarkerTextures_Blue
LoadCADistrict - Label: Hwy 267 at Brockway Summit
////
MapControls.Instance.SetMarkers(tempLng, tempLat, markerTexture, tempRow.locationName);
========== End Of Calling Script Code
Update: I Changed the call to feed actual data to the MapControls.SetMarkers function and now I ge the follwoing error:
======== Begin Error
NullReferenceException: Object reference not set to an instance of an object
MapControls.SetMarkers (Double tempLng, Double tempLat, UnityEngine.Texture2D tempTex, System.String tempLabel) (at Assets/_Scripts/MapControls.cs:193)
CCTVFileLoader.LoadCADistrict () (at Assets/_Scripts/CCTVFileLoader.cs:851)
CCTVFileLoader.StartMeUpCCTV () (at Assets/_Scripts/CCTVFileLoader.cs:86)
CCTVFileLoader.Start () (at Assets/_Scripts/CCTVFileLoader.cs:78)
========= End Error