Author Topic: Weird Unity Editor error with TNManager.playerData  (Read 1998 times)

kevinmore

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 5
    • View Profile
Weird Unity Editor error with TNManager.playerData
« on: December 02, 2014, 04:26:13 PM »
Hi Aren,

I'm make a ready room functionality, and I  use TNManager.playerData to synchronize the player's status to the host.

At first, I only assigned a bool value, it works perfectly. ie. TNManager.playerData = true;

After that, I made a struct which has more information of the player. I'm not quite sure if I'm assigning the player data in a right way. Here is what I did.

  1. private struct PlayerInfo
  2. {
  3.     public int playerID;
  4.     public string playerName;
  5.     public bool readyStatus;
  6.  }
  7. private PlayerInfo myInfo;
  8. private bool imReady = false;
  9. void Start()
  10.     {
  11.         // set up the local PlayerInfo
  12.         myInfo = new PlayerInfo();
  13.         myInfo.playerID = TNManager.playerID;
  14.         myInfo.playerName = "Dummy";
  15.         myInfo.readyStatus = imReady;
  16.  
  17.         // inform the info to the host
  18.         if (!TNManager.isHosting)
  19.         {
  20.             TNManager.playerData = myInfo;
  21.         }
  22.     }
  23.  

I run the program in the Unity Editor as a host, and run the exe as a host from windows. The first client connects successfully. However, when the second client attempts to connect, it fails and a strange error shows in the Unity editor:
[TNet] Error: (ThreadFunction Process) CompareBaseObjectsInternal 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.


I've tried to cast the PlayeyInfo to object, and it does not solve the problem.
  1. TNManager.playerData = (object)myInfo;

If the applications are not started from Unity Editor, everything is fine.

How to solve problem?

Thanks in advance!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Weird Unity Editor error with TNManager.playerData
« Reply #1 on: December 04, 2014, 04:32:09 AM »
I'm pretty sure this was fixed in TNet 2.0.2... what version do you have?