I trying to pass my parent variables to my child they are passing but I’m get a NullReferenceException: Object reference not set to an instance of an object. I checked all the answers on this and could not find an answer but I might of found a clue that my parent is not getting the child of my child but i’ll post the code down there i still get the same result If you could help (or direct me some one who knows how to fix this.). Help is much appreciated. (I cut out code parts that are not likely part of the problem.)
the Layered objects are:
Player (Parent Script here)
groundcheck
imported model
Material of model
HitBox(The Child Script here)
And the parent communication script
HitBoxCollider hitBox;
void start()
{
hitBox = transform.GetChild(1).GetComponentInChildren<HitBoxCollider>(); // also tried this this hitBox = transform.GetComponentInChildren<HitBoxCollider>();
}
void Update
{
HitBoxData();
}
void HitBoxData()
{ /*these are giveing me a NullReferenceException: Object reference not set to an instance of an object. */
hitBox.knockBackX = knockBackX1;
hitBox.knockBackY = knockBackY1;
hitBox.knockBackLength = knockBackLength;
hitBox.damageToGive = damageToGive;
}
And the child communication script
PlayerControls pc;
void Start () {
pc = transform.parent.GetComponentInParent<PlayerControls>();
}