- Home /
NullReferenceException: Object reference not set to an instance of an object iShake.Update () (at Assets/scripts/iShake.js:32)
I am new to javascript. I am executing the following unity script. I am getting the NullReferenceException on line 32. I will greatly helpful if anyone could identify the problem.
 #pragma strict
 
 import ThinksquirrelSoftware.Fluvio.Emitters;
 
 var accelerometerUpdateInterval : float = 1.0 / 60.0;
 var lowPassKernelWidthInSeconds : float = 1.0;
 var shakeDetectionThreshold : float = 2.0;
 
 internal var emitter : FluidEmitter;
 
 private var lowPassFilterFactor : float = accelerometerUpdateInterval / lowPassKernelWidthInSeconds; 
 private var lowPassValue : Vector3 = Vector3.zero;
 private var acceleration : Vector3;
 private var deltaAcceleration : Vector3;
 
 function Start()
 {
     shakeDetectionThreshold *= shakeDetectionThreshold;
     lowPassValue = Input.acceleration;
 }
 
 function Update()
 {
     acceleration = Input.acceleration;
         lowPassValue = Vector3.Lerp(lowPassValue, acceleration, lowPassFilterFactor);
         deltaAcceleration = acceleration - lowPassValue;
     if (deltaAcceleration.sqrMagnitude >= shakeDetectionThreshold)
     {
         Debug.Log("Shake event detected at time "+Time.time);
     }  else {
         Debug.Log("Shake event NOT DETECTED ");
         **emitter.Emit();**
     }
 }
Answer by Wolfram · Feb 02, 2013 at 01:31 AM
The reason is emitter is null. Where/how do you assign to it? Maybe recheck the docs or examples for Fluvio to learn how to properly set up a scenario. 
Answer by weenchehawk · Feb 02, 2013 at 01:11 AM
You may have posted the wrong script - the script you posted doesn't have a line 37.
Answer by Nabster · Feb 02, 2013 at 09:44 AM
I haven't initialized the emitter, which can is dont by initializing it on onStart() method.
 emitter = FluidEmitter.FindObjectOfType(FluidEmitter);
a) don't post responses as answers, use the comment button. this is a response to my answer
b) it is impolite to mark your own answer as accepted, especially if somebody else already answered your question correctly (=me).
c) there is no "onStart()" method; code in there will never be executed. use "Start()".
:), You're absolutely right. I receive your answers during the review process of my answer. However, technically, I have posted my answer first.
Hm, not according to the timestamps shown in the answers.
But anyway, glad your problem is solved! :o)
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                