How to instantiate "_Connection"?
Closed this issue · 3 comments
I was following the README instructions and I got stuck at "public WebSocketConnection _Connection" ;
Am I missing something? _Connection is null and unity always throws error when I try to do anything with it. Do I have to create my own object or is it somewhere and I missed something??
Sorry for noob questions, I'm trying to understand web sockets, first time using them
--- UPDATE ---
found a similar issue and used these two lines and it worked:
GameObject connectionObject = new GameObject("WebSocketConnection");
_Connection = connectionObject.AddComponent();
Hello, this sounds more like an issue learning how Unity GameObjects and Components work, not really a websocket issue.
The sample code doesn't walk you through a full project setup, it does assume you know how to work with those already.
You can see a video here https://youtu.be/qOZNvxveZXQ?t=164
--- UPDATE --- found a similar issue and used these two lines and it worked: GameObject connectionObject = new GameObject("WebSocketConnection"); _Connection = connectionObject.AddComponent();
I do not recommend you learn to do things in this way. It is unnecessary and inefficient vs using serialized fields.
I also recommend you take things one at a time. It might be easier to use a command line utility to learn websockets, but it is up to you and your learning style!
Thank you for the fast reply and suggestions! Yeah now everything makes sense. I managed to use the inspector to add a dedicated game object for the connection. I will read about this because I did get confused.
By the way, a million thanks for this great utility plugin!