get_gameObject can only be called from the main thread.
Is the error I am getting which I've figured out is to do with the way event handlers are implemented in C#.
In my Start method I have
EventManager.Instance.AddListener(EVENT_TYPE.UPDATE, this);
Then in my OnEvent handler method I have
public void OnEvent(EVENT_TYPE Event_Type, Component Sender, object Param=null)
{
//Detect event type
switch (Event_Type)
{
case EVENT_TYPE.UPDATE:
Debug.Log(" UPDATE Timer event received Param = "+ Param);
foo(Param as string);
break;
}
}
And then my foo method
private void foo(string param)
{
Debug.Log("ASSERT foo gameObject" + gameObject);
So gameObject
is null because the foo
method is not on the main thread. So how DO I access gameObject
then?