Why does this script have a Null error?

using UnityEngine;
using System.Collections;

public class pausebackers : MonoBehaviour {
public PlayMakerFSM theFsm;

	 void OnApplicationPause(bool paused)
{
      if (!paused)
      {
theFsm.FsmVariables.GetFsmBool("exit").Value = true;
      }
}
}

Why does this script have a Null error? and what is wrong with it?

Here is the error:NullReferenceException: Object reference not set to an instance of an object
pausebackers.OnApplicationPause (Boolean paused) (at Assets/pausebackers.cs:11)

I've never used PlayMaker, but if you have an unassigned variable theFsm , then you will get a null reference exception. If theFsm doesn't exist, then FsmVariables or anything else in that line doesn't exist, you cannot set it to anything. You need to assign it in the Inspector. Check the instructions for PlayMaker to see how to use it.

Comment as Answer: Please don't post comments in the answer area. Answers are for solutions to the problem. Post comments by selecting the [add new comment] link on the right bottom of the question and also on the bottom of each answer. Note comments do not go through moderation and will appear immediately.

1 Answer

1

This site explaines what you are looking for:

https://hutonggames.fogbugz.com/?W329

Also, what alucardj said is also true ofc.

Thanks Guys :)