Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by hydrow · Jun 26, 2013 at 04:45 PM · coroutineclassyieldnull reference exception4.1

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

UPDATE

I replicated the issue below in an empty project, confirmed it and posted it here.

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.

Comment
Add comment · Show 12
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kajos · Jun 27, 2013 at 09:01 AM 0
Share

$$anonymous$$aybe shared$$anonymous$$aterial ins$$anonymous$$d of material? Your errors don't seem to point to your code above btw.

avatar image Guidez · Jun 27, 2013 at 02:37 PM 0
Share

$$anonymous$$aybe this? (http://docs.unity3d.com/Documentation/ScriptReference/index.Writing_Scripts_in_Csharp_26_Boo.html[1] ) Coroutines have a different syntax in C#. Coroutines have to have a return type of IEnumerator and you yield using yield return ... ; ins$$anonymous$$d of just yield ... ;.

avatar image hydrow · Jun 27, 2013 at 04:03 PM 0
Share

@$$anonymous$$ajos We are sure that the function doesn't even get called at run time when yield is used, it is not related to materials. This function works perfectly in Unity 4.0

@Guidez We are using UnityScript, not C# or boo.

avatar image Guidez · Jun 27, 2013 at 04:50 PM 0
Share

If you comment out the "if" block in the while block, does it still fail?

avatar image hydrow · Jun 27, 2013 at 04:56 PM 0
Share

yes, it fails.

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

C# yield not doing anything 2 Answers

How to use yield within a class function 2 Answers

problem with using classes and coroutines 1 Answer

Yield Wait for Seconds (A little help here) 2 Answers

Need to call yield TWICE ??? (ANSWERED) 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges