- Home /
NullReferenceException on a FSM attribute
I'm using like example the wiki FSM scripts (http://wiki.unity3d.com/index.php?title=Finite_State_Machine) to create a finite state machine.
private FSMsystem fsm;
float tempo;
float timer=1.0f;
public void SetTransition(Transition t) { fsm.realizaTransicao(t); }
public void Start()
{
tempo=timer;
iniciaFSM();
}
public void Update()
{
if(tempo==timer) //p mostrar uma mensagem d cada vez (mensagem e resposta)
fsm.CurrentState.causaTransacao();
tempo-=Time.deltaTime;
if(tempo<0.0f)
{
fsm.CurrentState.realizaAcao();
tempo=timer;
}
}
private void iniciaFSM() //cria estados, adiciona transações, e adiciona estados à FSM
{
VitimaPotencialSempre stateVPS = new VitimaPotencialSempre();
stateVPS.AddTransition(Transition.Iniciativa, StateID.TentaAmizade);
AmizadePedida stateAmizade = new AmizadePedida();
stateAmizade.AddTransition(Transition.ProcessoConcluido, StateID.VPS);
fsm = new FSMsystem();
fsm.AddState(stateVPS);
fsm.AddState(stateAmizade);
}
However, at this my code above I got a NullReferenceException on the fsm (line 18) attribute and I don't understand why because on iniciaFSM function fsm is not null. Anyone know what I need to do to resolve this problem?
Answer by Ninita · Mar 19, 2013 at 12:23 PM
Ok, forget, there are one attribute at VitimaPotencialSempre constructor that isn't instantiate correctally and assumes like null, although any other variable is null in this code above
Your answer

Follow this Question
Related Questions
Name-fetching script working but with error. 1 Answer
Null reference exception on Screenpointtoray (Multiplayer) 1 Answer
Need Help With a NullReference Exception 2 Answers
NullReferenceException 1 Answer
Null Reference Exception Hunt ! 1 Answer