0

I think I am doing right, but I have "Object reference not set to an instance" error.

I have GolfDrive GameObject. Then Golf_drive2 animation is put under it. As shown in the first image.

enter image description here

Then I have a variable currentObject in my script and set Golf_drive2 to control the animation. As shown in the second image.

enter image description here

When I tried to access the animation as follow

var frame = currentObj.GetComponent<Animation>()[currentObj.name].time;

I have "Object reference not set to an instance of an object". What could be wrong?

EDIT: I changed as

var frame = 1.2f;
if (currentObj != null)
    frame = currentObj.GetComponent<Animation>()[currentObj.name].time;

That means currentObj is not null. Then still have the same error.

EDIT 2: I tested the animation as

Animation n = currentObj.GetComponent<Animation>();
if (n == null)
   Debug.Log("I AM NULL");

Nothing is printed, so animation is not null.

derHugo
  • 83,094
  • 9
  • 75
  • 115
batuman
  • 7,066
  • 26
  • 107
  • 229

0 Answers0