- Home /
C# How to access gameObject in main thread
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?
Comment
Your answer
Follow this Question
Related Questions
3d Models, How to turn invisible 3 Answers
Adding force to a bullet 3 Answers
Creating 3d planets with terrain and atmosphere 3 Answers
Sprites: Project Sprite to Mesh, allow for bending of sprites for 3d environments 0 Answers
Dice Value 1 Answer