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.
private struct PlayerInfo
{
public int playerID;
public string playerName;
public bool readyStatus;
}
private PlayerInfo myInfo;
private bool imReady = false;
void Start()
{
// set up the local PlayerInfo
myInfo
= new PlayerInfo
(); myInfo.playerID = TNManager.playerID;
myInfo.playerName = "Dummy";
myInfo.readyStatus = imReady;
// inform the info to the host
if (!TNManager.isHosting)
{
TNManager.playerData = myInfo;
}
}
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.
TNManager.playerData = (object)myInfo;
If the applications are not started from Unity Editor, everything is fine.
How to solve problem?
Thanks in advance!