transform.position assign attempt for 'Cubie' is not valid. Input position is { NaN, NaN, NaN }.

[36013-nan+error.png|36013]

So here’s some background information, I am trying to create this explosion effect of “cubie’s”. I have one object called enemy that when he collides with a bullet it destroys itself and instantiates another object called EnemyDeathAnimation which is not really an animation but a gameObject that replicates an explosion effect based on this tutorial: How to Make an Object Shatter Into Smaller Fragments in Unity

when I play the game and shoot the enemies occasionally I get the NaN error. I think it may be caused by the sphere used in the explosion effect instantiating and interfering with other objects. If anyone could shed some light on how to avoid/fix the error that would be great. If there is any better way of creating the explosion effect I would be more than happy to scratch this method and do it that way.

Enemy Script:
using UnityEngine;
using System.Collections;

public class EnemyCubeScript : MonoBehaviour 
{
	public GameObject deathAnimation;

	private float fadeTimer = 1.9f;
	private Transform player;
	private NavMeshAgent nav;

	void OnTriggerEnter (Collider col)
	{
		if(col.tag == "Bullet")
		{
			GameObject deathAnimationClone = Instantiate(deathAnimation, transform.position, transform.rotation) as GameObject; //instantiates deathAnimation gameObject
			Destroy (gameObject); //destroy self
			Destroy (deathAnimationClone, fadeTimer); 
			Destroy (col.gameObject); //destroy bullet
		}
	}
	void Awake () {
		player = GameObject.FindGameObjectWithTag ("Player").transform;
		nav = GetComponent <NavMeshAgent> ();
	}
	
	void Update () {
		nav.SetDestination (player.position);
	}
}

if(col.tag == “Bullet”)
{
GameObject deathAnimationClone = Instantiate(deathAnimation, transform.position, transform.rotation) as GameObject; //instantiates deathAnimation gameObject
Destroy (gameObject); //destroy self

BANG! End of script… and gameobject.

http://en.wikipedia.org/wiki/NaN - Look under ‘Operations generating NaN’. Divide by zero seems to be quite a common one.

It can also represent missing information, which is why I point out the gameobject destruction, as a case where info could be missing.

Also make sure the is information in all your variables. Its a safe practise to initialise them when you declare them.

11/29/14

It appears that if I remove the sphere causing the “cubies” to explode and changing its transform fixes the issue. It is not exactly the effect I was going for but will suffice for now.

==========================================================================================

12/11/14

I found that by by experimenting with the Unity particle system I was able to create the effect I was looking for and found this tutorial specifically useful: Making a Simple Game in Unity (Part 3) - Unity C# Tutorial - YouTube