Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

iTween causes NullReferenceException

Discussion in 'Scripting' started by Qualdan, Mar 11, 2013.

  1. Qualdan

    Qualdan

    Joined:
    Aug 5, 2011
    Posts:
    27
    I have few scripts with iTween based actions, but iTween started to cause NullReferenceException if I update code during playmode.

    The error comes if I enter playmode and then make modifications to any script (even one, where there are no iTween actions). I get the following error when Unity refreshes the script automatically:

    NullReferenceException: Object reference not set to an instance of an object
    iTween.TweenUpdate () (at Assets/Standard Assets/iTween/Plugins/iTween.cs:4624)
    iTween.Update () (at Assets/Standard Assets/iTween/Plugins/iTween.cs:6563)

    Any ideas of what is causing this? Or how I could get rid of it?


    Ps. I don't know if it matters, but iTween is placed in Standard Assets/iTween/Plugins -folder.
     
  2. Glockenbeat

    Glockenbeat

    Joined:
    Apr 24, 2012
    Posts:
    669
    I have the same in many (most/all) cases. Simple solution: Don't edit scripts in play mode.
     
  3. Qualdan

    Qualdan

    Joined:
    Aug 5, 2011
    Posts:
    27
    That's what I've been doing, but it produces stupid problems.

    I move an object 1 unit with iTween and then I go to play mode and see what it looks like. "Oh, it's not enough"
    I stop play mode, make the movement 2 units and enter the play mode again. "Now it's too much"
    I stop play mode again, alter movement to 1.5 units...

    iTween is an excellent tool, if it wouldn't make that error. I could make my movements and/or rotations usually with Mathf.Lerp, but iTween would make all that so much easier.
     
  4. Glockenbeat

    Glockenbeat

    Joined:
    Apr 24, 2012
    Posts:
    669
    Just to be more specific, I was not talking about iTween only, but instead I also saw that a lot with self built scripts. Seems like one can never tell if a script change during runtime will actually work, that's why I don't do that anymore and always restart the scene when I need to test a change. It's a bit of a hassle as you mentioned, but that way I am 100% sure that the errors occuring are caused by myself and not a hiccup during script compilation. ;-)
     
  5. Qualdan

    Qualdan

    Joined:
    Aug 5, 2011
    Posts:
    27
    Ah, yes. I do only small changes like the ones I mentioned during play mode.
    Bigger ones I always test with a restart.

    But the fact that iTween gives the error means there is a problem with it. There shouldn't be an error.
    Or am I doing something wrong with it?
     
  6. NobleAnarchist

    NobleAnarchist

    Joined:
    Mar 13, 2013
    Posts:
    2
    I'm with Qualdan - I would love to see this resolved. Making small incremental changes to some small bit of code somewhere shouldn't necessitate a complete restart due to iTween behaving poorly.

    Has anyone gotten anywhere with this?
     
  7. lorenalexm

    lorenalexm

    Joined:
    Dec 14, 2012
    Posts:
    307
    I think the statement of "iTween behaving poorly" can be negated by the fact that it is just bad practice to edit gameplay scripts while running the scene; you should expect errors to be thrown if you are changing a script during runtime. If the need to tweak the values during play mode is that high, expose some members to the inspector and update from there.