I'm stuck inside an Action :
socket.On("login", data => {
Debug.Log("1");
Debug.Log("2?");
Debug.Log(gameObject);
Debug.Log("1^^");
});
All I get is 1 and 2? on console. After calling the gameObject it freezes. Although other functions work, as they should. But if I just remove that gameObject, it works fine.
I've called gameObject from many different places, they simply log GameObject.
And the method it's referring to, its definition looks something like this :
public Emitter On(string eventString, Action<object> fn) {
ListenerImpl listenerImpl = new ListenerImpl(fn);
return this.On(eventString, (IListener) listenerImpl);
}
And this is type of System.Action.
Now my question is how can I access gameObject inside Action.
The socket.io library I'm using : https://github.com/Rocher0724/socket.io-unity
And logging outside the closure, it just logs. But when logging inside the library, I get :
UnityEngine.Debug:Log(Object)
<>c__DisplayClass3_0:<ActivePalyerCountStomp>b__0(Object) (at Assets/Scripts/Home.cs:26)
Socket.Quobject.EngineIoClientDotNet.ComponentEmitter.ListenerImpl:Call(Object[]) (at Assets/Socket/Quobject/EngineIoClientDotNet/ComponentEmitter/ListenerImpl.cs:26)
Socket.Quobject.EngineIoClientDotNet.ComponentEmitter.Emitter:Emit(String, Object[]) (at Assets/Socket/Quobject/EngineIoClientDotNet/ComponentEmitter/Emitter.cs:17)
Socket.Quobject.SocketIoClientDotNet.Client.QSocket:OnEvent(Packet) (at Assets/Socket/Quobject/SocketIoClientDotNet/Client/QSocket.cs:207)
Socket.Quobject.SocketIoClientDotNet.Client.QSocket:OnPacket(Packet) (at Assets/Socket/Quobject/SocketIoClientDotNet/Client/QSocket.cs:178)
Socket.Quobject.SocketIoClientDotNet.Client.QSocket:<SubEvents>b__21_0(Object) (at Assets/Socket/Quobject/SocketIoClientDotNet/Client/QSocket.cs:59)
Socket.Quobject.EngineIoClientDotNet.ComponentEmitter.ListenerImpl:Call(Object[]) (at Assets/Socket/Quobject/EngineIoClientDotNet/ComponentEmitter/ListenerImpl.cs:26)
Socket.Quobject.EngineIoClientDotNet.ComponentEmitter.Emitter:Emit(String, Object[]) (at Assets/Socket/Quobject/EngineIoClientDotNet/ComponentEmitter/Emitter.cs:17)
Socket.Quobject.SocketIoClientDotNet.Client.Manager:OnDecoded(Packet) (at Assets/Socket/Quobject/SocketIoClientDotNet/Client/Manager.cs:233)
Socket.Quobject.SocketIoClientDotNet.Client.Manager:<OnOpen>b__50_1(Object) (at Assets/Socket/Quobject/SocketIoClientDotNet/Client/Manager.cs:217)
Socket.Quobject.EngineIoClientDotNet.ComponentEmitter.ListenerImpl:Call(Object[]) (at Assets/Socket/Quobject/EngineIoClientDotNet/ComponentEmitter/ListenerImpl.cs:26)
Socket.Quobject.EngineIoClientDotNet.ComponentEmitter.Emitter:Emit(String, Object[]) (at Assets/Socket/Quobject/EngineIoClientDotNet/ComponentEmitter/Emitter.cs:17)
Socket.Quobject.SocketIoClientDotNet.Parser.Decoder:Add(String) (at Assets/Socket/Quobject/SocketIoClientDotNet/Parser/Parser.cs:120)
Socket.Quobject.SocketIoClientDotNet.Client.Manager:OnData(String) (at Assets/Socket/Quobject/SocketIoClientDotNet/Client/Manager.cs:225)
Socket.Quobject.SocketIoClientDotNet.Client.Manager:<OnOpen>b__50_0(Object) (at Assets/Socket/Quobject/SocketIoClientDotNet/Client/Manager.cs:209)
Socket.Quobject.EngineIoClientDotNet.ComponentEmitter.ListenerImpl:Call(Object[]) (at Assets/Socket/Quobject/EngineIoClientDotNet/ComponentEmitter/ListenerImpl.cs:26)
Socket.Quobject.EngineIoClientDotNet.ComponentEmitter.Emitter:Emit(String, Object[]) (at Assets/Socket/Quobject/EngineIoClientDotNet/ComponentEmitter/Emitter.cs:17)
Socket.Quobject.EngineIoClientDotNet.Client.Socket:OnPacket(Packet) (at Assets/Socket/Quobject/EngineIoClientDotNet/Client/Socket.cs:236)
Socket.Quobject.EngineIoClientDotNet.Client.EventPacketListener:Socket.Quobject.EngineIoClientDotNet.ComponentEmitter.IListener.Call(Object[]) (at Assets/Socket/Quobject/EngineIoClientDotNet/Client/Socket.cs:490)
Socket.Quobject.EngineIoClientDotNet.ComponentEmitter.Emitter:Emit(String, Object[]) (at Assets/Socket/Quobject/EngineIoClientDotNet/ComponentEmitter/Emitter.cs:17)
Socket.Quobject.EngineIoClientDotNet.Client.Transport:OnPacket(Packet) (at Assets/Socket/Quobject/EngineIoClientDotNet/Client/Transport.cs:115)
Socket.Quobject.EngineIoClientDotNet.Client.Transport:OnData(String) (at Assets/Socket/Quobject/EngineIoClientDotNet/Client/Transport.cs:105)
Socket.Quobject.EngineIoClientDotNet.Client.Transports.WebSocket:ws_MessageReceived(Object, MessageReceivedEventArgs) (at Assets/Socket/Quobject/EngineIoClientDotNet/Client/Transports/WebSocket.cs:64)
Socket.WebSocket4Net.Default.WebSocket:FireMessageReceived(String) (at Assets/Socket/WebSocket4Net/Default/WebSocket.cs:295)
Socket.WebSocket4Net.Command.Text:ExecuteCommand(WebSocket, WebSocketCommandInfo) (at Assets/Socket/WebSocket4Net/Command/Text.cs:5)
Socket.WebSocket4Net.Default.WebSocket:ExecuteCommand(WebSocketCommandInfo) (at Assets/Socket/WebSocket4Net/Default/WebSocket.cs:389)
Socket.WebSocket4Net.Default.WebSocket:OnDataReceived(Byte[], Int32, Int32) (at Assets/Socket/WebSocket4Net/Default/WebSocket.cs:399)
Socket.WebSocket4Net.Default.WebSocket:client_DataReceived(Object, DataEventArgs) (at Assets/Socket/WebSocket4Net/Default/WebSocket.cs:201)
Socket.WebSocket4Net.SuperSocket.ClientEngine.ClientSession:OnDataReceived(Byte[], Int32, Int32) (at Assets/Socket/WebSocket4Net/SuperSocket.ClientEngine/ClientSession.cs:114)
Socket.WebSocket4Net.SuperSocket.ClientEngine.AsyncTcpSession:ProcessReceive(SocketAsyncEventArgs) (at Assets/Socket/WebSocket4Net/SuperSocket.ClientEngine/AsyncTcpSession.cs:62)
Socket.WebSocket4Net.SuperSocket.ClientEngine.AsyncTcpSession:SocketEventArgsCompleted(Object, SocketAsyncEventArgs) (at Assets/Socket/WebSocket4Net/SuperSocket.ClientEngine/AsyncTcpSession.cs:25)
System.Threading._ThreadPoolWaitCallback:PerformWaitCallback()
And this socket.on is being called from Start() directly. No additional context.
Main purpose of this is to get some component of that gameobject :
string playerRoute = Defaults.baseApi + "/player/count";
JsonRestClient restClient = GetComponent<JsonRestClient>();
restClient.Get<BaseDto>(playerRoute, "onSuccess", "onError");
ConcurrentQueuewhere you put the incoming messages (e.g. thedatayou're receiving). Then on the main thread you consume the queue. \$\endgroup\$