UserVariable Null Reference Exception

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

Posts: 6
Joined: 05 May 2012, 18:27

UserVariable Null Reference Exception

Postby philliamapps » 01 Aug 2012, 05:40

Hey all! I have been making a game in which the user spawns an object, and I have been using the ObjectMover example's UserVariables in order to transmit information from the client to the server, and then back to the the clients.

Code: Select all

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sfs2X;
using Sfs2X.Core;
using Sfs2X.Entities;
using Sfs2X.Entities.Data;
using Sfs2X.Entities.Variables;
using Sfs2X.Requests;
using Sfs2X.Logging;

public class NetworkManager : MonoBehaviour
    public void SpawnNewObject(double x, double y, double z, double roty, int numObj) {
      List<UserVariable> userVariables = new List<UserVariable>();
      userVariables.Add(new SFSUserVariable("x", x));
      userVariables.Add(new SFSUserVariable("y", y));
      userVariables.Add(new SFSUserVariable("z", z));
      userVariables.Add(new SFSUserVariable("rot1", roty));
      userVariables.Add(new SFSUserVariable("numObj", numObj));
      smartFox.Send(new SetUserVariablesRequest(userVariables));          // <------- Error: Null Reference exception

With most of the code cut out, this was the section that returned an error: "NullReferenceException: Object reference not set to an instance of an object"

Could any of you geniuses please help me out? Thanks a ton!

User avatar
Site Admin
Posts: 21014
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: UserVariable Null Reference Exception

Postby Lapo » 07 Aug 2012, 08:18

Are you sure you are using the latest C# API?
...addicted to flash games
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Re: UserVariable Null Reference Exception

Postby ThomasLund » 10 Aug 2012, 12:11

If thats the entire code (I hope not), then it should not compile. Where is the smartFox variable set?

In that line, smartFox variable is the only thing possibly null. So 99% certain that you are not initializing it correctly.

Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter:

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 4 guests