I use Unity3d for android platform,
I'm getting an error like below when I try to show a game object in onRoomJoin
event.
get_gameObject can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
UnityEngine.Component:get_gameObject()
SFSConnect:OnRoomJoin(BaseEvent) (at Assets/SFSConnect.cs:861)
Sfs2X.Core.EventDispatcher:DispatchEvent(BaseEvent)
Sfs2X.SmartFox:DispatchEvent(BaseEvent)
Sfs2X.Controllers.SystemController:FnJoinRoom(IMessage)
Sfs2X.Controllers.SystemController:HandleMessage(IMessage)
Sfs2X.Core.SFSProtocolCodec:DispatchRequest(ISFSObject)
Sfs2X.Core.SFSProtocolCodec:OnPacketRead(ByteArray)
Sfs2X.Core.SFSIOHandler:HandlePacketData(ByteArray)
Sfs2X.Core.SFSIOHandler:OnDataRead(ByteArray)
Sfs2X.Bitswarm.BitSwarmClient:OnSocketData(Byte[])
Sfs2X.Core.ThreadManager:ProcessItem(Hashtable)
Sfs2X.Core.ThreadManager:InThread()
Here is my code as shown below:
public class SFSConnect : MonoBehaviour {
public GameObject obj;
void Start () {
img = obj.GetComponent<Image> ();
img.obj.SetActive (false);
}
void onRoomJoin(BaseEvent evt)
{
img.obj.SetActive (true);
}
}