Topic: uGUICustomMarkerEngineExample Crashing on Type Cast

I am trying to use the uGUICustomMarkerEngineExample but the script crashes from a null reference exception.  In the AddMarkerAddMarker(double lng, double lat, string text) function the following code is causing this error:

public static uGUICustomMarkerExample AddMarker(double lng, double lat, string text)
{
     GameObject markerGameObject = Instantiate(_instance.markerPrefab) as GameObject;
     (markerGameObject.transform as RectTransform).SetParent(_instance.markerContainer);
     ...
}

Casting markerGameObject.transform as RectTransform dynamically returns null and then calling .SetParent(...) on a null value crashed the script.

I tried attaching this script to the map object in the Demo Scene and set the markerPrefab and the markerContainer in the editor.
I also noted that markerGameObject.transform is a non-null Transform object prior to the cast. Is there any reason why this cast is returning null?

Tested this issue using Unity 5.4.1f1 and OnlineMaps versions 2.5.1.1 and 2.5.1.2

Re: uGUICustomMarkerEngineExample Crashing on Type Cast

Hello

Using this example, you need to specify two fields:
Marker Container - GameObject, which will contain markers. It must be a Canvas or child GameObject.
Marker Prefab - UI element that will be drawn as a marker.

So there you have one of two problems:
Marker Container is not canvas or child GameObject.
Marker Prefab is not UI element.

Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.

Re: uGUICustomMarkerEngineExample Crashing on Type Cast

Hi Alex,

Thanks for the response. My issue was that the Prefab was not a UI Element. I have it working now!