Websockets + WebGL throwing exception, Unity 5.4 doesn't allow AddComponent(MonoBehaviour)!

Options
EDIT: It looks like Unity 5.4 simply doesn't allow attached MonoBehaviour with AddComponent(). Any help would be appreciated, I literally can't connect until this is resolved :(

When connecting to PUN in Unity 5.4, it's throwing two (related) exceptions:

1) "AddComponent with MonoBehavior is not allowed." It references line 79 of SocketWebTcp.cs which does precisely what it says is not allowed (it's trying to add monobehaviour with addcomponent).
2) This then causes a null reference, not shocking where it didn't allow mb to be added, at line 84 of SocketWebTcp.cs where it attempts to do this: this.sock = new WebSocket(new Uri(ServerAddress));

Best Answers

Answers

  • skeptika
    Options
    It does look like Unity just changed it: http://forum.unity3d.com/threads/please-clarify-using-gameobject-addcomponent-is-no-longer-allowed-and-will-throw-an-exception.412199/

    Sorry to be an explicit newb, but since the advice is to "Derive a class from MonoBehaviour and add it instead," how would I do this in the context of SocketWebTcp.cs?
  • skeptika
    Options
    Ty this worked beautifully, feel like a newb for not actually knowing how to do this, but appreciate the assist!

    Heads up for the Photon guys, 5.4 brought (which is already out in RC) a few breaking changes that'll have to be changed in Photon to avoid seeing a ton of forum messages like this! ;) In addition to breaking .AddComponent(MonoBehaviour), they also broke several of the OnSomethingHappened references, removing the On in most cases. Cheers and thanks!
  • skeptika
    Options
    Yah that's what caught me by surprise, I'd been using 5.4 for awhile in betas with no problems, then suddenly boom it didn't work. All good and thanks!