NullReferenceException: Update DOMoveX End Value mid tween.
« on: January 11, 2016, 12:00:10 AM »
I am trying to create something similar to the follow script example that you have provided. In my scenario I am trying to update the tweens destination location via script. So rather than a true follow I just need to access and manipulate mid tween. For some reason I am getting a NuffRef though my script is quite similar to your follow.cs example. Below is the relevant code. I am getting the null reference when trying to change the end value.

Code: [Select]
Tweener shipLaneTween;

void Start () {
    //Start Tween For Lane Switching
    shipLaneTween = transform.DOMoveX(LM.laneArray [shipLaneDestination].x, 0.5f).SetAutoKill(false);
}

void FixedUpdate () {
    if (shipLaneCurrent != shipLaneDestination) {
        SwitchLane ();
    }
}

public void SwitchLane(){
    shipLaneTween.ChangeEndValue(LM.laneArray [shipLaneDestination].x,true).Restart();
}
« Last Edit: January 11, 2016, 12:12:08 AM by Leonardherndon »

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: NullReferenceException: Update DOMoveX location mid tween.
« Reply #1 on: January 11, 2016, 12:14:04 AM »
Hi!

With single-axis tweens, you still have to pass a full Vector3 when changing the end/start value. That's because a single-axis tween is actually tweening via a Vector3, even if the other axes are ignored. Just change to this:

Code: [Select]
// The other axes will be ignored so just insert a 0 there
shipLaneTween.ChangeEndValue(new Vector3(LM.laneArray [shipLaneDestination].x, 0, 0),true).Restart();

Cheers,
Daniele

P.S. that's my bad for not making this clearer in the docs. Will update them

Re: NullReferenceException: Update DOMoveX End Value mid tween.
« Reply #2 on: January 11, 2016, 12:26:21 AM »
Although that may help me avoid any future issues, that change did not have any effect on my problem. It seems to be losing the reference or the reference is not being set correctly. Here is a screenshot of the script: http://puu.sh/mr6xy/c8e12d7e47.png (Excuse the Mess).

Code: [Select]
NullReferenceException: Object reference not set to an instance of an object
Ship.SwitchLane () (at Assets/Scripts/Ship.cs:245) <-- [POINTS TO shipLaneTween.ChangeEndValue]
Ship.FixedUpdate () (at Assets/Scripts/Ship.cs:177)

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: NullReferenceException: Update DOMoveX End Value mid tween.
« Reply #3 on: January 11, 2016, 12:50:42 AM »
Uhm that is weird. Are you sure you're not calling SwitchLane from some other script, when shipLaneTween has not yet been initialized? Can you set a series of logs before the ChangeEndValue, to verify if shipLaneTween is different from NULL and if LM.laneArray is also different from NULL? Also, can you copy/paste here the entire error log message, so I can check it out better?

Re: NullReferenceException: Update DOMoveX End Value mid tween.
« Reply #4 on: January 11, 2016, 01:41:00 AM »
With that information I was able to figure out that the child class was overriding the start method. So sorry to waste your time with that.

*

Daniele

  • Dr. Admin, I presume
  • *****
  • 378
    • View Profile
    • Demigiant
Re: NullReferenceException: Update DOMoveX End Value mid tween.
« Reply #5 on: January 11, 2016, 10:41:21 AM »
No worries, glad it's solved ;)