Null Reference Exception after updating from 4.0 to 4.1.5 (coroutines)

Hello,

I posted the issue below to answers.unity3d.com, but it is rather a technical issue.

I have a piece of code that works perfectly on Unity 4.0, however after I updated my unity version to 4.1.5, it is not working properly anymore.(it is also broken on 4.1.2) Precisely, I am getting a null reference exception while attemping to call a function which is a coroutine, whose type is IEnumerator. I made sure that all parameters are valid and I can access the function.

This function is being called from a javascript object.(a class instance of a GO) And the function is on a seperate object.

function showSimpleEffect ( c : GameObject, effectName : String, duration : float, scale : Vector3 ) : IEnumerator{
 
    var simpleEffect : GameObject = Instantiate( simpleEffectPlanePrefab , c.transform.position + Vector3(0,0.4,0) , simpleEffectPlanePrefab.transform.rotation );
    simpleEffect.transform.localScale = scale;
    simpleEffect.renderer.materials[0].SetTexture("_MainTex", Resources.Load("simpleSfxTextures/" + effectName ));
    simpleEffect.transform.parent = c.transform;
 
    var rate = 1.0/duration;
    var t = 0.0;
 
    while (t < 1.0) {
 
       t += Time.deltaTime * rate;
 
       if( t <= 0.4 ){
         simpleEffect.renderer.material.SetColor ( "_Color", Color( Mathf.Lerp( 0.5, 0.5, t*2.5 ) , Mathf.Lerp( 0.5, 0.5, t*2.5 ), Mathf.Lerp( 0.5, 0.5, t*2.5 ) , Mathf.Lerp( 0.0, 1.0, t*2.5 ) ) );
       }else if( t >= 0.6 ) {
         simpleEffect.renderer.material.SetColor ( "_Color", Color( Mathf.Lerp( 0.5, 0.5, (t-0.6)*2.5 ) , Mathf.Lerp( 0.5, 0.5, (t-0.6)*2.5 ),Mathf.Lerp( 0.5, 0.5, (t-0.6)*2.5 ), Mathf.Lerp( 1.0, 0.0, (t-0.6)*2.5 ) ) );
       }
 
       yield;
    }
 
    Destroy(simpleEffect);
 
}

This is a very simple function that shows an image above a gameobject for a number of seconds. I have to point out that if I remove the while loop, the function works properly. (Probably because it is not a coroutine anymore)

I don’t know what the developers of Unity changed after 4.0 but I can’t figure it out by myself, any help or clue is appreciated.

Here is the error we get, however it points to the line which we call the function.

NullReferenceException
Effect.onActivate (Boolean applyResult) (at Assets/Scripts/cardFunctions.js:2098)
Effect.setActiveness (Boolean applyResult) (at Assets/Scripts/cardFunctions.js:1849)
Effect.onAdd () (at Assets/Scripts/cardFunctions.js:2540)
cardFunctions.addEffect (UnityEngine.GameObject onWhichCard, .Effect effectToAdd) (at Assets/Scripts/cardFunctions.js:2690)
cardProperties.onPlay () (at Assets/Scripts/cardProperties.js:2887)
mastermind+$moveCardToSlotEnemy$1164+$.MoveNext () (at Assets/Scripts/mastermind.js:1538)

Thanks in advance.

Think I’m experiencing the same thing. Today I updated from 4.1.4 to 4.1.5. It’s the first time I ever update Unity and I’m a complete newbie. Everything was working just fine earlier today. But now I get like 999+ errors after 4 seconds of play. NullRefferenceExceptions

I restored my computer system to an earlier state, so now I’m running 4.1.4 but I see my latest changes are still there and the errors are still to be seen in the console :frowning:

I replicated the issue in an empty project and posted a new thread, so this can be closed.

Link to new thread:
http://forum.unity3d.com/threads/188057-Coroutine-calls-from-Class-instances-are-BROKEN!-%28worked-in-4-0%29