I’m working in a small multiplayer game based on the Island demo, and using the SmartFox Server.
Lately, I’ve been trying to integrate the Character Customization demo (the dressing room to be precise) before the island loads (right after the login scene), so the user can choose its character and enter the island with it.
The problem I’m having is that for some reason, Unity freezes everytime I try to access the island after choosing the character I’m going to use (I have a button saying “Go to the Island!” to load the Islands scene).
I’m trying to use C# when generating the character and I’m following the same steps as in DressingRoom:
while (!CharacterGenerator.ReadyToUse) yielding();
CharacterGenerator generator = CharacterGenerator.CreateWithRandomConfig();
while (!generator.ConfigReady) yielding();
GameObject remotePlayer = generator.Generate();
Anyway, Unity freezes when accesing “ConfigReady”, exactly at this point:
foreach (CharacterElement c in currentConfiguration.Values) {
if (!c.IsLoaded) return false;
}
And I have no idea why.
I’ve tried the VirtualWorldDemo way (In Javascript) and it works fine, but I would like to do it in C# for a better integration in the code.
Can anybody figure out why this could happen? It may be because the currentConfiguration variable gets corrupted for some reason?
You cannot start a Coroutine in C# without StartCoroutine. So to make it work, you need:
while (!CharacterGenerator.ReadyToUse) yield return StartCoroutine(yielding());
Of course this makes the yielding function rather ackward in use. You should therefire just write yield return 0 directly instead of using your yielding function.
Note that the function with the while loop will also need to be an IEnumerator and started with StartCoroutine, or it still won’t work.