Question by
MasonCommunicationsVR · Aug 11, 2017 at 07:21 AM ·
c#animatorvrgetcomponentanimator controller
Editing other object's animator parameter... NullReferenceException? (VR)
I am creating a VR program using VRTK and I would like the user to be able to reach out and touch an object, which will change an animator parameter on another object to trigger an animation. I was able to get this to work when I called the other object's animator from my hand controller, but the exact same script is not working in the interactive object. I just get the error "NullReferenceException: Object reference not set to an instance of an object" on this line: anim = otherObject.GetComponent();
Here is the rest of the relevent code:
Animator anim;
GameObject otherObject;
/// <summary>
/// Allowed controller type.
/// </summary>
/// <param name="Both">Both controllers are allowed to interact.</param>
/// <param name="Left_Only">Only the left controller is allowed to interact.</param>
/// <param name="Right_Only">Only the right controller is allowed to interact.</param>
public enum AllowedController
{
Both,
Left_Only,
Right_Only
}
private void Start()
{
GameObject otherObject = GameObject.FindWithTag("Player");
anim = otherObject.GetComponent<Animator>();
}
public virtual void StartUsing(GameObject currentUsingObject)
{
anim = otherObject.GetComponent<Animator>();
anim.SetInteger("size", 1);
Any help would be extremely appreciated! Thanks
Comment