itisnajim / SocketIOUnity

A Wrapper for socket.io-client-csharp to work with Unity.
MIT License
406 stars 69 forks source link

The object does not create itself. #61

Closed Ozgurlegelisiyoruz closed 1 year ago

Ozgurlegelisiyoruz commented 1 year ago

My Connect Manager code does not generate itself when I get any export. It works in Unity Editor but my code does not work when I get any export. My code is as follows;

using System;
using System.Collections;
using System.Collections.Generic;
using Newtonsoft.Json;
using UnityEngine;
using SocketIOClient;
using UnityEngine.SceneManagement;
using SocketIOClient.Newtonsoft.Json;
using Random = UnityEngine.Random;

public class ConnectManager : MonoBehaviour
{
    public static ConnectManager Instance;
    public SocketIOUnity socket;
    public GameObject loadingPanel;
    private string idGoogle;

    private void Awake()
    {
        if (!Instance)
        {
            Instance = this;
            DontDestroyOnLoad(this);
        }
        else
        {
            Destroy(gameObject);
        }

        ConnectSocket();
    }

    public void ConnectSocket()
    {
        var uri = new Uri("myserver");

        socket = new SocketIOUnity(uri, new SocketIOOptions
        {
            Query = new Dictionary<string, string>
            {
                {"token", "UNITY"}
            },
            EIO = 4,
            Transport = SocketIOClient.Transport.TransportProtocol.WebSocket
        });
        socket.OnConnected += (sender, e) => { Debug.LogError(e.ToString()); };
        socket.OnError += (sender, e) => { Debug.LogError(e.ToString()); };
        socket.OnDisconnected += (sender, e) => { Debug.LogError(e.ToString()); };
        socket.Connect();
        Debug.LogError("adad "+  socket.Connected);
        socket.JsonSerializer = new NewtonsoftJsonSerializer();
    }

}

Everything works as it should in the Editor. I don't get any error log. Only my object is not set at start. In Android build etc (i test with logcat dont have any error) object is always null)

Ozgurlegelisiyoruz commented 1 year ago

So in short, the problem is that the script does not create itself on android.

Ozgurlegelisiyoruz commented 1 year ago

I fixed this problem via upgrade my unity version (to 2022.2.20f1)