Quantcast
Channel: Questions in topic: "4.1"
Viewing all articles
Browse latest Browse all 45

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

$
0
0
***UPDATE*** I replicated the issue below in an empty project, confirmed it and posted it [here.][1] 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. 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. [1]: http://forum.unity3d.com/threads/188057-Coroutine-calls-from-Class-instances-are-BROKEN!-%28worked-in-4-0%29

Viewing all articles
Browse latest Browse all 45

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>