Hi, I have an issue that is driving me mad, and it happens only in builds, everything works fine when I play my game in the editor.
This code from my attack hitbox that tests to see if it hits the enemy collision capsule and then activates some scripts on it, works just fine. But when I create a windows build I am not able to hit the enemies and this is what I get in the log every time I take a swing at the enemies:
"Enemy_Collision is hit
NullReferenceException: Object reference not set to an instance of an object
at Hitbox.OnTriggerEnter (UnityEngine.Collider collision) [0x0004f] in :0 "
This is the part of my code that gives me the problem:
void OnTriggerEnter(Collider collision)
{
if(collision.gameObject.CompareTag("Enemy_Collision"))
{
Debug.Log("Enemy_Collision is hit");
EnemyHealthController _enemyHealthController = collision.gameObject.GetComponentInParent<EnemyHealthController>();
if(_enemyHealthController)
{
Debug.Log("HealthController FOUND");
_enemyHealthController.currentHealth = _enemyHealthController.currentHealth - damage;
_enemyHealthController.UpdateHealth();
Vector3 position = collision.transform.position + new Vector3(0f, 1f, 0f);
Instantiate(enemyHitParticles, position, collision.transform.rotation);
audioManager.Play("swordHitFlesh01");
audioManager.Play("monsterPain02");
//Knockback
enemyAI = collision.transform.parent.gameObject.GetComponent<EnemyAI>();
enemyAI.SetKnockbackValues(knockbackForce, transform.parent.position);
}
else
{
Debug.Log("HealthController NOT found");
}
}
If you have any suggestions what I can do to make this work in builds as well I would be very grateful