enter code hereI am working on AR game, using AR foundation, whenever I run it I get the error: NullReferenceException: Object reference not set to an instance of an object UIManager.Update () , I had it solved by referencing the object in the scene, but I get another error: NullReferenceException: Object reference not set to an instance of an object EventManager.TriggerEvent (System.String eventName, System.Collections.Generic.Dictionary`2[TKey,TValue]
I don't really know how to deal with that and this is the code:
private static EventManager eventManager;
public static EventManager instance
{
get
{
if (!eventManager)
{
eventManager = FindObjectOfType(typeof(EventManager)) as EventManager;
if (!eventManager)
{
Debug.LogError("There needs to be one active EventManger script on a GameObject in your scene.");
}
else
{
eventManager.Init();
}
}
return eventManager;
}
}
void Init()
{
if (eventDictionary == null)
{
eventDictionary = new Dictionary<string, Action<Dictionary<string, object>>>();
}
}
public static void StartListening(string eventName, Action<Dictionary<string, object>> listener)
{
Action<Dictionary<string, object>> thisEvent = null;
if (instance.eventDictionary.TryGetValue(eventName, out thisEvent))
{
// Add the called function to the action
thisEvent += listener;
// Renew the dictionary with the action
instance.eventDictionary[eventName] = thisEvent;
}
else
{
thisEvent += listener;
instance.eventDictionary.Add(eventName, thisEvent);
}
}
public static void StopListening(string eventName, Action<Dictionary<string, object>> listener)
{
if (eventManager == null) return;
Action<Dictionary<string, object>> thisEvent = null;
if (instance.eventDictionary.TryGetValue(eventName, out thisEvent))
{
thisEvent -= listener;
instance.eventDictionary[eventName] = thisEvent;
}
}
public static void TriggerEvent(string eventName, Dictionary<string, object> message)
{
Action<Dictionary<string, object>> thisEvent = null;
if (instance.eventDictionary.TryGetValue(eventName, out thisEvent))
{
thisEvent.Invoke(message);
}
}
}