game room options issues
Options
Hello.
I have been having a number of issues with 'JoinOrCreateRoom' and 'CreateRoom' methods of PUN.
My main issue is that not matter how I try to set the room options, a number of them (always the same ones) never get set. Namely 'isVisible = false' and 'isOpen = false'.
If I try to set these options in either 'JoinOrCreateRoom' or 'CreateRoom', they are always set to true and testing by joining with a second client has shown that this is not just a false positive so-to-speak. However, the 'maxplayers' variable does set properly in 'CreateRoom'.
Secondly, if I try to set the 'maxplayers' property in 'JoinOrCreateRoom', I get the error 'InvalidCastException: Cannot cast from source type to destination type.' which directs me to the line 'this.maxPlayersField = (byte)propertiesToCache[GameProperties.MaxPlayers];' in RoomInfo.cs.
I have tried casting the 'maxplayers' value to byte also to no avail.
Code tried:
I have been having a number of issues with 'JoinOrCreateRoom' and 'CreateRoom' methods of PUN.
My main issue is that not matter how I try to set the room options, a number of them (always the same ones) never get set. Namely 'isVisible = false' and 'isOpen = false'.
If I try to set these options in either 'JoinOrCreateRoom' or 'CreateRoom', they are always set to true and testing by joining with a second client has shown that this is not just a false positive so-to-speak. However, the 'maxplayers' variable does set properly in 'CreateRoom'.
Secondly, if I try to set the 'maxplayers' property in 'JoinOrCreateRoom', I get the error 'InvalidCastException: Cannot cast from source type to destination type.' which directs me to the line 'this.maxPlayersField = (byte)propertiesToCache[GameProperties.MaxPlayers];' in RoomInfo.cs.
I have tried casting the 'maxplayers' value to byte also to no avail.
Code tried:
//throws error at max players PhotonNetwork.JoinOrCreateRoom(UniqueID, new RoomOptions() { maxPlayers = 1, isVisible = false, isOpen = false }, TypedLobby.Default); //isVisible and isOpen are true on creation PhotonNetwork.JoinOrCreateRoom(UniqueID, new RoomOptions() { isVisible = false, isOpen = false }, TypedLobby.Default); //isVisible and isOpen are true on creation PhotonNetwork.CreateRoom(UniqueID, new RoomOptions() { maxPlayers = 1, isVisible = false, isOpen = false }, TypedLobby.Default);
0
Comments
-
I can reproduce the issue and I have a workaround. I don't know yet why it doesn't work though.
If you create a RoomOptions instance "ro" and set ro.isVisible = false, then it works, as far as I can see.
I don't understand why the initializer doesn't work though. I will find out.0 -
It seems to be an issue with initializers in Unity. Testing the same code in the MS DotNet Runtime, the code works.
This part of the code was copied from a pure dotnet API, so the effect wasn't discovered (as our demos show rooms).
I reported a bug to Unity and I will have to check what we can do to fix this.0 -
It works if the bool RoomOptions are properties and set in the RoomOptions constructor.
Auto generated properties with get;set; are enough.
I will try to have a look at similar code, when time allows.0 -
That's for the reply
I have other areas I can work on for now so I'll get to that until some other way around is worked out.0 -
I am not sure if I will do another update of PUN 1.28 and the next proper release will be a bigger update which is a few days off.
I found by now, that this is a known issue since years in Unity. I reported it for a beta of Unity 5. If you can access the beta, please report this issue, too. It might add some weight to fixing it.
Just to recap:
You can avoid the issue by not using the Object Initializer syntax. Create a new RoomOptions object and then (!) assign values. This is the easiest way!
Or: Modify RoomOptions to use C# properties with a backup field which initializes the values to what they are now by default.0 -
Same issue in the Win Phone 8 SDK / Load Balancing.
The workaround of setting the RoomOptions fields does not work
Flavio0