Page 1 of 1

unity3 and smartfox user variables

Posted: 15 Oct 2010, 13:45
by appels

I'm trying to use user variables in SmartFox to spawn my player's avatar type but it's working for now.
what i have is this :

Code: Select all

   void onUserEnterRoom(int roomId, User user) {
      Hashtable uVars = new Hashtable();
      uVars = user.GetVariables();
      aTypes.Add(user.GetId(), uVars["avatarType"]);

As soon as a player enters the room, i retrieve the variables.
That part works fine when i debug it.
Now in my remote player spawn function i try this :

Code: Select all

string tmp = GetVars.aTypes[user.GetId()].ToString();

but when i do that i get following error from unity :

NullReferenceException: Object reference not set to an instance of an object
PlayerSpawnController.SpawnRemotePlayer (SmartFoxClientAPI.Data.User user) (at Assets/Scripts/PlayerSpawnController.cs:52)
PlayerSpawnController.SpawnRemotePlayers () (at Assets/Scripts/PlayerSpawnController.cs:45)
PlayerSpawnController.SpawnPlayers () (at Assets/Scripts/PlayerSpawnController.cs:22)
GetVars:OnJoinRoom(Room) (at Assets/Scripts/GetVars.cs:52)
GetVars:FixedUpdate() (at Assets/Scripts/GetVars.cs:47)

Anyone have an idea ?

Re: unity3 and smartfox user variables

Posted: 05 Aug 2012, 17:47
by Carl Lydon
I get the same thing in SFS2X unity C#
The docs are not good.

Re: unity3 and smartfox user variables

Posted: 07 Aug 2012, 09:55
by rjgtav
Have you checked the Object Movement example, which shows how to set and retrieve user variables?

You can also check this topic:

Re: unity3 and smartfox user variables

Posted: 07 Aug 2012, 17:42
by Carl Lydon
I just switched to retrieving the variables individually, instead of using getVars and now it works.